I have simple script:
#!/bin/sh
#NOTE - this script does not work!
#column=${1:-1}
column=1+1
awk '{print $'$column'}'
But when run
ls -la | ~/test/Column.sh
I receive always
1
1
1
1
What the problem?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your script is equivalent to:
Awk tries to add one to the first column of the output of
ls -alin your example, which is the file type and mode bits. That’s not a number, so it gets converted to 0. Add one to zero, and you get your output.See here:
If you want the shell to calculate the number, try:
or even