I have below shell script test.sh
#!/bin/bash
var=$1
echo $var
It gives un-expected output unless I pass command line argument value $-123
in single quote
#./test.sh $-123
himBH123
#./test.sh '$-123'
#$-123
I want to pass special character $-123
to this script.
I know usual way is to pass it in single quote like '$-123'
or backlash
e.g.
test.sh '$123'
OR
test.sh $123
Is there anyway to solve this by any change inside shell script.
So that user can pass ./test.sh $-123
without single quote.
Reason I am asking is, in real time, we are passing multiple arguments to our script. Out of that one argument will be having password which will have this special character.
So just mentioning to pass only particular argument inside single quote ''
and rest without any single quote will look strange or there are huge chances that customer might miss to pass single quote.