I have done very little programming in C++, and I am not really understanding how to use code in KornShell (ksh) on the Knoppix OS. The resources given to us by the professor has been little, so it is hard to work out. The two text books we have for class talks mostly about commands in variations of UNIX, though little to do with ksh.
Write a shell script that accepts exactly one argument which must be a positive integer. (My second one has two)
Ksh Code:
NUMBER=$1 read -p NUMBER # Test that one argument was input. if [[ $# -ne 1 ]];then echo "Please enter an integer as an argument" exit 1 elif [[ $NUMBER -le 0 ]];then # Test value of argument is less than or equal to zero echo "Please enter a number > 0" exit 1 fi while [["$NUMBER" -ne 1]];do printf $NUMBER if [[$NUMBER -gt 1]];then printf "," fi NUMBER=$(($NUMBER-1)) done printf $NUMBER When I run this from the shell I keep getting "Please enter an integer as an argument" as an output, though the entry was 3, or something like that.
I noticed that there was not anything for user input, so I tried to enter this myself with
read -p NUMBER before the if statement.
What am I missing from the code to continue on with the rest of the script to be run?