0

I was trying a simple shell program as below to append data at the end of the file,

path="/root/dir"
secure="*(rw,..)"
echo "$path $secure" >> a.txt

is not appending the string to a.txt

11
  • Is it not appending anything to a.txt? Can you show output of ls -l a.txt? Commented Aug 4, 2014 at 13:57
  • -rw-r--r-- 1 root root 25 Aug 4 07:44 a.txt Commented Aug 4, 2014 at 14:03
  • cat a.txt adasdasdasasd adasdasdas Commented Aug 4, 2014 at 14:03
  • 1
    Hmm ok and how about echo "$path" >> a.txt Commented Aug 4, 2014 at 14:16
  • 1
    Could it be that the * is giving problems? What if you try to set secure with some content that does not contain asterisk? In bash, * is expanded. You could also try secure='*(rw,..)' (single quote), so that it does not expand. Commented Aug 4, 2014 at 14:45

1 Answer 1

1

Just a guess but your script may be in DOS format that you're actually trying to write output to a.txt\r instead. Try to run one of the following to your code and try again:

sed -i 's|\r||' file
dos2unix file
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.