Hot answers tagged

5

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'


5

grep -F 'word1 word2' infile or, if you prefer on one line: grep -F -e 'word1' -e 'word2' infile


5

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 ...


3

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 ...


2

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


2

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 ...


2

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" ...


1

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 ...



Only top voted, non community-wiki answers of a minimum length are eligible