1

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?

Ramesh
  • 102
  • 10

1 Answers1

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