How to set the From email address for mailx command?
You can use the “-r” option to set the sender address: mailx -r me@example.com -s …
You can use the “-r” option to set the sender address: mailx -r me@example.com -s …
fish isn’t and never tried to be compatible with POSIX sh. This really just means that it’s a separate language (like Java, Python or Ruby) rather than an implementation or extension of sh (like Bash, Dash and Ksh). Obviously, just like you can’t copy-paste Java snippets into a Python program, you can’t copy-paste sh code … Read more
The POSIX and portable way to compare strings in the shell is if [ “$HOSTNAME” = foo ]; then printf ‘%s\n’ “on the right host” else printf ‘%s\n’ “uh-oh, not on foo” fi A case statement may be more flexible, though: case $HOSTNAME in (foo) echo “Woohoo, we’re on foo!”;; (bar) echo “Oops, bar? Are … Read more
for f in $(find . -name “FILE_NAME”); do grep PATTERN $f | tail -1; done
I found shellcheck: it tests for common errors in quoting and other things you overlook (“because it works”).
Two simple examples to capture output the pwd command: $ b=$(pwd) $ echo $b /home/user1 or $ a=`pwd` $ echo $a /home/user1 The first way is preferred. Note that there can’t be any spaces after the = for this to work. Example using a short script: #!/bin/bash echo “hi there” then: $ ./so.sh hi there … Read more
If you’re using GNU find, then find path -printf “%f\n” will just print the file name and exclude the path.
No, tr is specifically intended to replace single characters by single characters (or, depending on command-line options, to delete characters or replace runs of a single character by one occurrence.). sed is probably the best tool for this particular job: $ echo “asdlksad ~ adlkajsd ~ 12345” | sed ‘s/~/~\n/g’ asdlksad ~ adlkajsd ~ 12345 … Read more
You need to escape the backtick, but also escape the backslash: $ touch 1\` $ /bin/sh -c “ls 1\\\`” 1` The reason you have to escape it “twice” is because you’re entering this command in an environment (such as a shell script) that interprets the double-quoted string once. It then gets interpreted again by the … Read more