Hi,
if the user just inputs the return key, then you will have an empty string in your T1 variable. So, your code would end up like this:
Code:
bash script Want to capture return key and assign a value
Hi
I want to prompt a user to enter a value if he press enter I want to assign a default value in a if statement.
#!/bin/bash
echo -en "Enter a value : "
read T1
if [ "$T1" == "" ]; then
T1="pepe"
fi
Consider two things:
1) To compare two strings you need to use the == operator (almost sure that it's best than just = )
2) The most important thing is that in your particular example, you dont need an else clause. If the user input something, then you dont want to change so you dont need to execute any code. If the user hasnt input a thing, then you will change and continue.
I hope this is useful
Cheers!