I want to print string called "$1". But when I do this with echo it prints string which equals to "$1" variable. How can I print "$1" just like string?
for example:
set -- "output" # this sets $1 to be "output" echo $1 # ==> output
But I want this:
echo $1 # ==> $1
To print a string in Bash, use echo command. Provide the string as command line argument to echo command.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script.
$2 is the second command-line argument passed to the shell script or function. Also, know as Positional parameters.
$_ (dollar underscore) is another special bash parameter and used to reference the absolute file name of the shell or bash script which is being executed as specified in the argument list. This bash parameter is also used to hold the name of mail file while checking emails.
You have to escape the $
to have it shown:
$ echo "\$1"
or, as noted by JeremyP in comments, just use single quotes so that the value of $1
does not get expanded:
$ echo '$1'
You need to either:
echo '$1'
$
sign: echo "\$1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With