I’m writing a script that asks the user for several options and then, via a series of echo statements, creates and writes to a separate script file. That script will also be dependent on at least one command line argument when executed.
Given the original statement
if [ "` echo $1 | egrep ^[[:digit:]]+$`" = "" ]
that determines if the first argument ($1) is an integer, how can I include that in the echo statement to be written to the new file while maintaining the command line argument access?
I tried to escape the double quotes and dollar signs like
echo "if [ \"` echo \$1 | egrep ^[[:digit:]]+\$`\" = \"\" ]" >> generatePanos
but that just resulted in
if [ "" = "" ]
However, echo "\$1" results in $1 being printed in the file.
I’m not entirely certain what you mean, but here are two things you can try:
If you’re trying to print the entire line as-is (including the
$1), use single-quotes to tellechoto not interpret anything:If you’re trying to print the entire line but substitute in the current value for
$1:If you’re trying to substitute the entire portion of the command that’s in backticks (evaluated using the current value of
$1), it’s probably best to use an intermediate variable: