PDA

View Full Version : Retaining variable info if no input



cbillson
February 15th, 2013, 06:11 PM
I'm wanting to have defaults to some questions in a test script so i can just press enter if no data changes - currently though it sets the variable to blank... any help on how i can stop it doing this?

In this example i want $testvar to remain as no, however it sets it blank

testvar=no

read -p "change a setting $testvar : " testvar

echo $testvar

steeldriver
February 15th, 2013, 06:32 PM
Have a look at the ${parameter-default}, ${parameter:-default} constructs here

http://tldp.org/LDP/abs/html/parameter-substitution.html

cbillson
February 18th, 2013, 11:24 AM
That worked great - thanks

Bucky Ball
February 18th, 2013, 11:55 AM
Thread moved to Programming Talk.