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?
Asked
Active
Viewed 695 times
1
-
1You really shouldn't edit your question to mean something entirely different. – Benjamin W. Aug 11 '17 at 21:29
-
I edited the question.please check again.sry for the inconvenience – Ramesh Aug 11 '17 at 21:29
-
The duplicate still applies, though. – Benjamin W. Aug 11 '17 at 21:30
-
1I really hope `*(^%567590ihyg` isn't your password... – dimo414 Aug 11 '17 at 21:42
-
I'm voting to close this question as off-topic because it is not strictly about a programming issue. – Rob Kielty Aug 11 '17 at 23:24
1 Answers
1
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}"

Petr Skocik
- 58,047
- 6
- 95
- 142
-
-
-
3Please don't solicit upvotes - you'll get them if your question/answer merits it. – dimo414 Aug 11 '17 at 21:43