0

i am trying to access file email.txt in the script (directory of .txt file and the script is same)

!#bin/bash
total="$(wc -l < email.txt | tr -d ' ')"
echo "$total"

it's showing permission denied. Thankyou for any help

chepner
  • 497,756
  • 71
  • 530
  • 681
user2831683
  • 967
  • 1
  • 10
  • 21

1 Answers1

0

Well, there's at least one syntax error on your first character. Next give your script execute permissions,

$ cat test.sh
#!/bin/bash

total="$(wc -l < email.txt | tr -d ' ')"
echo "$total"
$ chmod 755 test.sh
$ ./test.sh
0

But then I have an empty "email.txt" file.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • you are setting the permissions for test.sh, but the file that is needed to be accessed is email.txt, dont we need to set permissions for that – user2831683 Feb 26 '14 at 20:05
  • @user2831683 You must have permission to read the file, else how did you create it and the script in the same folder? – Elliott Frisch Feb 26 '14 at 20:42
  • text file is not being created through the script, it is just a text file. – user2831683 Feb 26 '14 at 20:54
  • Doesn't matter. Unless it was created by a script run by a different user, you should be fine; if otherwise, there are some choices beyond giving it world read permission (which will work of course). – Elliott Frisch Feb 26 '14 at 21:02