![]() ![]() $ source script.sh 'python -c "print(7)"' To save you the trouble of imagining, you have to do this:īash: eval: line 9: syntax error near unexpected token `(' So the end result is the same.īoth of these solutions look pretty gross, but to put it in perspective, imagine what you have to do to use a doubly nested eval! ![]() (remember the only exceptions to double quotes are $, \, and `, not '). Much like the first, except that instead of escaping the single quotes they are enclosed in double quotes, since they block the evaluation of the single quotes.The result of the evaluation is that eval is passed the literal string echo '$HOME' as desired. This is concatenated with '$HOME', which just gets evaluated to the string $HOME, and finally another literal single quote is appended. The string echo is concatenated with the escaped literal \', which is taken to simply be a single quote string due to the backslash.The two eval commands above work in much the same way. The second example clarifies that both strings do not have to be in quotes. Here, the two strings “hel” and “lo” are simply concatenated when executing the command. This quote completely prevents bash from evaluating a command. The most basic kind of quote is the single quote ('). Hence the purpose of quotes: they are used to prevent bash from evaluating text that you would like to leave as a string. Obviously that’s not what that program is supposed to do. So, before that string makes it to the python command,īash attempts to evaluate it, determines that it is invalid bash syntax (since it’s not bash it’s python), and throws an error. However parentheses are special characters in bash. Print(7) is a completely valid python command that prints the number 7, The second example runs python, using the -c command to execute python code passed as a string. Therefore it evaluates the contents of this variable, which is my home directory (/home/austin). The argument fed to it is $HOME, which due to the dollar sign is interpreted as a bash variable. The first fragment uses the command echo, which naturally echos the argument to feed to it. Bash: syntax error near unexpected token `(' ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |