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?

5
  • 1
    You really shouldn't edit your question to mean something entirely different. Commented Aug 11, 2017 at 21:29
  • I edited the question.please check again.sry for the inconvenience Commented Aug 11, 2017 at 21:29
  • The duplicate still applies, though. Commented Aug 11, 2017 at 21:30
  • 1
    I really hope *(^%567590ihyg isn't your password... Commented Aug 11, 2017 at 21:42
  • I'm voting to close this question as off-topic because it is not strictly about a programming issue. Commented Aug 11, 2017 at 23:24

1 Answer 1

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}"
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the help sir:) and please upvote the ques
@Ramesh Please upvote the ans? :)
Please don't solicit upvotes - you'll get them if your question/answer merits it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.