2

I have this standard input:

read -p "Server-Number: " servernumber

The Server numbers goes from 01 - 99 It is important, that the number has a zero (01, 02, 03, ..., 10, 11, ..., 99) How can I edit the variable, if the number is only 1 instead of 01 ?

Sorry for my bad english ;) I hope your understand my question.

3 Answers 3

4
servernumber=`printf %02d $servernumber`
Sign up to request clarification or add additional context in comments.

1 Comment

Assuming you are using bash 4 or later: printf -v servernumber "%02d" "$servernumber".
1

Bash only, no other processes:

servernumber=0$servernumber         # add leading 0
servernumber=${servernumber: -2}    # take last 2 characters

Comments

0

write an if condition for checking the value of

echo $servernumber | nawk '/0/{print NR}' == 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.