Hello guys i'm using ubuntu 11, and I'm doing some shell scripting with it. the only problem i face it right now is "read" show it value, i don't know how it happening with mE cuz this the 1st. time i use "read" and i can see the value of it !!!! any way here is my codes:
#!/bin/bash
echo -n "Which file you want 2 store: "
read fname
echo -n "Do u want 2 delete file $fname in its current location? [Y\N]: "
read ansr
sudo tar -c -v -f The_Store.tar $fname
sudo chmod 700 The_Store.tar
if [ "$ansr" = "Y" ]; then
rm $fname
fi
echo "Congrats, ur file been stored"
the value of "fname" shows up after the user answer the Q: Do u want 2 delete file $fname in its current location?. Could any one help mE with this.
All what i want is to keep the value of "fname" hiding ..
$() – the command substitution. ${} – the parameter substitution/variable expansion.
There is no difference if you do not put $* or $@ in quotes. But if you put them inside quotes (which you should, as a general good practice), then $@ will pass your parameters as separate parameters, whereas $* will just pass all params as a single parameter.
Read-only Variables Shell provides a way to mark variables as read-only by using the read-only command. After a variable is marked read-only, its value cannot be changed. /bin/sh: NAME: This variable is read only.
From the bash
manpage part about read
:
-s Silent mode. If input is coming from a terminal, characters are not echoed.
In case your shell's read
buildin does not support -s
option you can also use stty
command:
echo "Which file you want 2 store: "
stty -echo
read fname
stty echo
echo "Do u want 2 delete file $fname in its current location? [Y\N]: "
stty -echo
read ansr
stty echo
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