1

Team,

looks simple but am unable to catch it. Am trying to read a file from user and store its contents into variable. My echo is working as its printing the file but my cat is not working.

read -p "specify the file to read nodes from: " file
echo $file

file_contents=$(cat $file | awk -F ',' '{print $1}')

for item in $file_contents
do
echo $item
done;

output

$HOME\backup\file.log

no such file
cat $HOME\backup\file.log

expected output

\home\users\backup\file.log

item1
item2
item3
3
  • How are you running the script? Commented May 6, 2020 at 17:38
  • I figured out the issue.. I cannot input the filepath as $HOME.. its not expanding it. when i enter absolute path its working. Commented May 6, 2020 at 17:42
  • You shouldn't be using for there, BTW. See mywiki.wooledge.org/BashFAQ/001 Commented May 6, 2020 at 21:08

1 Answer 1

1

The file with should be entered with absolute path and not $HOME.

so providing whole file path worked for me.

if there is a way I can use $HOME. Please advise.

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.