New answers tagged quoting
I (nearly) always quote everything to "echo", so I would do the above like: #!/bin/bash echo "./yowsup/yowsup-cli demos --s $1 \"$2\" -c yowsup/config &" ./yowsup/yowsup-cli demos --s $1 "$2" -c yowsup/config & The difference with @muru solution is, that there the original echo command is run "in the background" - here it's echoing to the screen ...
If you need $date inside the variable var: var='file.$date.txt' That will keep the $ inside the variable: $ echo "$var" | grep '\$' file.$date.txt
Use single quotes around variables to prevent shell expansion. Example echo '$file' will not expand $file. Edit after comment below: You can escape the $ sign int the var variable with var="file.\$DATE.txt".
I guess the question is why read -d '' works though read -d'' doesn't. The problem doesn't have anything to do with read but is a quoting "problem". A "" / '' which is part of a string (word) simply is not recognized at all. Let the shell show you what is sees / executes: start cmd:> set -x start cmd:> echo read -d " " foo + echo read -d ' ' foo ...
The problem isn't tar, it's in your shell code. The argument of the -C option is supposed to be a path, not a wildcard pattern. Notice that you had exactly the same problem with the cd command. You stored a wildcard pattern in the INSTALL_DIR variable. When you write -C $INSTALL_DIR, this applies the “split+glob” operator: take the value of the variable, ...
When the * is not quoted the shell expands the argument list before running the command. It passes the expand argument list to the program. When the * appears in a quoted string it is not expanded by the shell before being passed to the program. Try expanding the path, assigning it to another variable, and then quoting the second variable when passing it ...
Check your single quotes. Single quotes don't magically nest. alias sll 'ls -l \!* | grep -oE '\''[^ ]+$'\'' | xargs ls -ld --' That's still flawed for several reasons: Because of [^ ], that won't work for file or link target names that contain spaces. as you're treating that list as a list of lines, that won't work with file/link target names that ...
This can be done by using the $'\n' syntax (see http://stackoverflow.com/a/3182519/3822464). So for example: fgrep word1$'\n'word2 Or you can wrap the whole PATTERN that way (credit don_crissti) fgrep $'word1\nword2\nword3'
grep -F 'word1 word2' infile or, if you prefer on one line: grep -F -e 'word1' -e 'word2' infile
In case anybody has the same question, here is the script I wound up with: #!/bin/bash FILENAME="backup-$(date +%Y-%m-%d).tar.gz" echo $FILENAME tar -czvf /tmp/$FILENAME /home/pi/ lftp << EOF set ftps:initial-prot set ftp:ssl-force true set ftp:ssl-protect-data true open -u "USERNAME","PASSWORD" ...
You are asking two different questions. In reverse order: A better alternative might be rsync. It's as easy as FTP but a lot smarter. I highly recommend it. Your variables are not resolving because you have them encapsulated with single quotes. Observe: $ foo=bar $ echo $foo bar $ echo '$foo' $foo $ echo "$foo" bar If you rework your command such that ...
Top 50 recent answers are included