Reputation: 6809
I have script that accepts passwords from user. As we know passwords can have special characters. So there is case when user have some specific characters the script I wrote does not work.
Have a look
./passwrd.sh sohan$23
sohan3
Here is script snippet
#!/bin/sh
#=============================================================================
#
# DESCRIPTION
#
# Script for creating csbuser in weblogic
#
# USAGE ./create.sh <password>
# where password is OPTIONAL.
if [ $# -eq 1 ]; then
echo $1
#csb_password=`echo "$1" | sed -r 's/\$/\\\$/g'`
fi
Can anyone suggest me what can be done here.
Upvotes: 0
Views: 1563
Reputation: 289505
When you call the script like ./passwrd.sh sohan$23
, the $23
will be expanded.
To give it as a literal string, do use single quotes:
./passwrd.sh 'sohan$23'
$ cat a
#!/bin/bash
echo "the var is $1"
$ var=10
$ ./a a$var
the var is a10
$ ./a 'a$var'
the var is a$var
Upvotes: 1