bash - Why doesn't nohup sh -c "..." store variable? -


why doesn't "nohup sh -c" stores variable?

$ nohup sh -c "ru=ru" & [1] 17042 [1]+  done                    nohup sh -c "ru=ru" $ echo ${ru}  $ ru=ru $ echo ${ru} ru 

how make such store variable value can use in loop later?

for now, it's not recording value when use ru=ru instead bash loop, i.e.

nohup sh -c "ru=ru; file in *.${ru}-en.${ru}; some_command ${ru}.txt; done" & 

it doesn't work within sh -c "..." too, cat nohup.out outputs nothing echo:

$ nohup sh -c "fr=fr; echo ${fr}" & [1] 17999 [1]+  done                    nohup sh -c "fr=fr; echo ${fr}" $ cat nohup.out  

why doesn't "nohup sh -c" stores variable?

environment variables live in process, , potentially children of process. when run sh -c creating new child process. environment variables in child process cannot "move up" parent process. that's how shells , environment variables work.

it doesn't work within sh -c "..." too, cat nohup.out outputs nothing echo"

the reason using double quotes. when use double quotes, shell variable expansion before running command. if switch single quotes, variable won't expanded until shell command runs:

nohup sh -c 'fr=fr; echo ${fr}' 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -