0

I started to take lesson to learn bash script. I want to write a bash script that asks a user to enter an integer and counts the number of digits.

How can I use x=$(($x+1)) to increment my counter?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • You can omit **second** `$` but the syntax is correct. See: `x=3; x=$(($x+1)); echo "$x"` – Cyrus Apr 19 '20 at 11:47
  • Could you share your code with me cause I am really confused. –  Apr 19 '20 at 11:48
  • Take a look at this answer (https://stackoverflow.com/a/13727116/3121039) and the Bash FAQ (http://mywiki.wooledge.org/BashFAQ/024) and this analysis (https://askubuntu.com/questions/385528/how-to-increment-a-variable-in-bash). – Eric Bolinger Apr 19 '20 at 18:50

1 Answers1

0

simple_code.sh

echo "Enter a number"
read num
echo "Number of digits in your number = ${#num}"

run

bash simple_code.sh
axnet
  • 5,146
  • 3
  • 25
  • 45