DIRNAME=`dirname \`which $0\``
PREFIX=`cd $DIRNAME && cd .. && pwd`
DIRNAME=$(dirname `which $0`)
PREFIX=$(cd $DIRNAME && cd .. && pwd)
grep `whois \`fetch -qo - https://www.myexternalip.com/raw\` | grep country | awk '{ print $2 }'` zone.tabs
Not sure if this is a syntax error or if I'm trying to do something which can't be done...Unmatched '`'.
a=`do foo`
b=`other $a`
c=`$b elefant`
grep `whois \`fetch -qo - https://www.myexternalip.com/raw\` | grep country | awk '{ print $2 }'` zone.tabs
fetch -qo - https://www.myexternalip.com/raw
gives me a single IP address. So what are you trying to grep from that? See: grep(1): grep [-abcdDEFGHhIiJLlmnOopqRSsUVvwxZz] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color[=when]]
[--colour[=when]] [--context[=num]] [--label] [--line-buffered]
[--null] [pattern] [file ...]
whois `fetch -qo - https://www.myexternalip.com/raw` | grep country | awk '{ print $2 }'
, this gives me:peter@zefiris:/home/peter $ w` | grep country | awk '{ print $2 }' <
NL
No time to debug it for you, but these really complex things are hard to debug.
Suggestion: Break it into little bits, and put the bits into variables:
and so on. If you do this, you can develop it one step at a time, and debug it by checking the content of the variables after each baby step.Code:a=`do foo` b=`other $a` c=`$b elefant`
country=$(whois `fetch -qo - https://www.myexternalip.com/raw` | awk '/country/ { print $2 }') && grep $country zone.tabs
#!/bin/sh
country=$(whois `fetch -qo - https://www.myexternalip.com/raw` | awk '/country/ { print $2 }')
grep $country zone.tab
Yes you can. But I think you have to quote them; that may depend on the shell. I just tried it 2-levels deep in bash, and it worked fine:
It is still insane. If someone were to try 3 levels deep, they deserve to be hit with a stick.Code:echo foo `echo bar \`echo blatz\``
IP=`fetch -qo - https://www.myexternalip.com/raw`
COUNTRY=`whois $IP | grep country | awk '{print $2}'`
ZONE=`grep $COUNTRY zone.tab | awk '{print $3}'`
echo ln -s /usr/share/zoneinfo/$ZONE /etc/localhost
If you can put the following into one line with backticks three levels deep you have my permission to hit me with a stick
Code:IP=`fetch -qo - https://www.myexternalip.com/raw` COUNTRY=`whois $IP | grep country | awk '{print $2}'` ZONE=`grep $COUNTRY zone.tab | awk '{print $3}'` echo ln -s /usr/share/zoneinfo/$ZONE /etc/localhost
echo ln -s /usr/share/zoneinfo/`grep \`whois \\\`fetch -qo - https://www.myexternalip.com/raw \\\` | awk '/country/ { print $2 }' \` /usr/share/zoneinfo/zone.tab | head -n1 | awk '{ print $3 }'` /etc/localhost
echo $((`echo $((\`echo $((\\\`echo $((\\\\\\\`echo $((\\\\\\\\\\\\\\\`echo $((\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`echo 1\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`+1))\\\\\\\\\\\\\\\`+1))\\\\\\\`+1))\\\`+1))\`+1))`+1))
Code:echo ln -s /usr/share/zoneinfo/`grep \`whois \\\`fetch -qo - https://www.myexternalip.com/raw \\\` | awk '/country/ { print $2 }' \` /usr/share/zoneinfo/zone.tab | head -n1 | awk '{ print $3 }'` /etc/localhost
Had to add "head -n1" because e.g. "DE" is listed twice in the zone.tab.
Now just let me get that bamboo stick...
In [T]csh, double quotes are used for this purpose:
Code:echo "`echo start "\`""\`""\`"echo "\""hello "\"""\`""\`"echo "\""world "\"""\`""\`"echo end"\`""\`""\`""\`""\`"`"
echo `echo start` `echo hello` `echo world` `echo end`
/bin/sh
, there are no issues with nesting quotes or "backticks" when in the form of $()
: prefix="$(cd "$(dirname "$(realpath "$(which "$0")")")" && pwd)"
prefix="`cd "`dirname "`realpath "`which "$0"`"`"`" && pwd`"
I was studying how to nest backticks in [T]csh back then. The provided syntax is incorrect, but the following is correct.This does exactly the same....
Code:echo `echo start` `echo hello` `echo world` `echo end`
echo "`echo start "\"\`"echo hello "\"\\\"\\\`\""echo world "\"\\\"\\\\\\\"\\\\\\\`\\\"\""echo end"\"\\\"\\\\\\\`\\\\\\\"\\\"\\\`\\\"\"\`\""`"
May or may not be relevant but I notice that in/bin/sh
, there are no issues with nesting quotes or "backticks" when in the form of$()
:
prefix="$(cd "$(dirname "$(realpath "$(which "$0")")")" && pwd)"
cmd="pkg -r /mnt install -y $(cat <<PKG | tr '\n' ' ')"
drm-kmod
mc
PKG
echo $cmd