1

I have this code:

for dir in "/Users/vskumar/Dropbox/alexa"/*
do
  echo $dir
  value=`cat $dir`
  echo value
done

and the first file in the directory has the name as below:

amazon_alexa_february_7__2017_at_0504pm (2).txt

The output I get is:

/Users/vskumar/Dropbox/alexa/amazon_alexa_february_7__2017_at_0504pm (2).txt
cat: /Users/vskumar/Dropbox/alexa/amazon_alexa_february_7__2017_at_0504pm: No such file or directory
cat: (2).txt: No such file or directory

Basically, it is treating everything after space as another file name. How to fix it?

1 Answer 1

2

You need to use double quotes around your variables to prevent word splitting and globbing:

for dir in "/Users/vskumar/Dropbox/alexa"/*
do
  echo "$dir"
  value=`cat "$dir"`
  echo value
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.