Odd problem with making a variable the output of a command in a shell script
All I want to do is change the value of a number that was recently typed in. This is a simple script that shows exactly what I want to do:
#!/bin/bash
echo "Enter a number"
read num
num='expr $num - 1'
echo $num
Assuming the user entered 2, the output of the program, according to everything that I have read, should be 1. However, the output is expr $num - 1. I have no idea why it is doing that instead of evaluating. I know the problem is related to surrounding the expression with ''. I tried another script that used the whoami command to check to see if it was being run by root. However, 'whoami' didn't output the user name but instead whoami.
|