I am running a bash script that asks me a username and a password every time it executes.I want to keep the default as Arjun, *(^%567590ihyg. Is there a way to do that?
1 Answer
Use can use:
: "${x:=the_default_value}"
to set x to the string the_default_value if it's empty or unset.
The syntax is POSIX and is documenting along with related syntaxes at http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 .
In your case, you can attempt to read the variable or get it through a positional argument:
read name #or name=$1
and then default it if it is empty like so:
: "${name:=Arjun}"
3 Comments
Ramesh
Thanks for the help sir:) and please upvote the ques
Petr Skocik
@Ramesh Please upvote the ans? :)
dimo414
Please don't solicit upvotes - you'll get them if your question/answer merits it.
*(^%567590ihygisn't your password...