getting bash code to print from within bash
I'm trying to use bash instead of flash cards for my linux+. I have some testing materials I'm trying to write into a bash script that will ask you a question from the test. It works on almost every question, except a few that explicitly use bash commands within the question, for example:
Code:
What word will complete an if statement in bash such as the following: if [ -x "$file" ]; then echo Code:
#!/bin/bash Code:
./LX0-104_studyguide.sh: line 38: syntax error near unexpected token `then' More importantly, how can I get bash to blindly print code without trying to interpret it? Thank you. |
Try using the single quotes, not the double ones.
|
it is showing you what it wrong
Code:
if [ -x "$file" ]; then echo" <--- incomplete echo statement. Plus the quote looks like it is hitting the echo command too. Not exactly knowing what code you want printed out but these examples should get you an idea of how to, then go from there. Code:
Quote:
Code:
echo "mv -v /usr/file /usr/file3" example: Code:
userx%slackwhere ⚡ ~ ⚡> file="pppp" example 2 Code:
userx%slackwhere ⚡ ~ ⚡> echo "if [[ -x \$file ]] ; then |
The bash interpreter strips the "(double quote)'s so you need to escape them or bypass interpretation with '(single quote)'s.
$ echo the thing the thing $ echo "the thing" the thing $ echo "\"the thing\"" "the thing" $ echo '"the thing"' "the thing" This applies for other "special characters" as well $ echo $(( 2 + 2 )) 4 $ echo "$(( 2 + 2 ))" 4 $ echo "\$(( 2 + 2 ))" $(( 2 + 2 )) $ echo '$(( 2 + 2 ))' $(( 2 + 2 )) HTH |
Quote:
Code:
cat <<EOF |
A super powerful but under used tool is putting a $ at the start of single quotes:
Code:
$ echo 'the\nthing' |
All times are GMT -5. The time now is 09:15 PM. |