1

My first shell script

#!/bin/bash
echo "Input your file"
read $file
path=(readlink -f $file)
echo "$USER, $path" >> scriptlog.txt

it said missing operand. How can I fix it?

2

Replace your code with this one, and try :

#!/bin/bash
echo "Input your file"
read file
path=$(readlink -f "$file")
echo "$USER, $path" >> scriptlog.txt
| improve this answer | |
2

You missed $ in line path=(readlink -f $file), the correct one:

path=$(readlink -f $file)

Also note that, there're many flaws in your script:

  • Using read without -r
  • Forgetting double quotes variables

The quick fix:

#!/bin/bash
echo "Input your file"
IFS= read -r file
path=$(readlink -f "$file")
echo "$USER, $path" >> scriptlog.txt
| improve this answer | |
  • Anh Cường Việt Nam à. nếu được anh team view giúp em nhé. Em cám ơn rất nhiều ạ – H.Dinh Apr 21 '16 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.