开发者

Exporting a variable with a backslash

开发者 https://www.devze.com 2023-02-18 21:37 出处:网络
I am working on an install script, of the following form: # get username echo \"Please enter your oracle username:\"

I am working on an install script, of the following form:

# get username
echo "Please enter your oracle username:"
read -p "> " username
stty -echo

# get password
echo "Please enter your oracle password:"
read -r -p "> " password; echo
stty echo

# -- Create all text to output to 开发者_开发百科config
finaluser=$usernamelabel$username
finalpassword=$passwordlabel$password
echo -e $finaluser"\n"$finalpassword > $configfile

The problem is, if a password of the form like 'z\2z', it is outputted to $configfile as:

z^Bz

Is there any easy way to avoid this?


Don't embed the \n, and then you don't need the -e option which is also interpreting the \2.

echo "$finaluser" >$configfile
echo "$finalpassword" >>$configfile

or

cat >$configfile <<EOF
$finaluser
$finalpassword
EOF

or a third way if you really want to use a single command

printf '%s\n%s\n' "$finaluser" "$finalpassword"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号