./script.sh: line 8: /etc/passwd: Permission denied

788 views Asked by At

I have this script which I can't execute:

#!/bin/bash

USERS="/etc/passwd"

for user in `$USERS | cut -f 1 -d ':'`
do
        echo $user
done

This is the output of ls -l script.sh:

-rwxrwxrwx 1 user user 94 Jul 30 21:24 script.sh

What am I doing wrong? :| I also tried running it as root and with sudo and nothing worked...it's annoying...

1

There are 1 answers

0
glenn jackman On BEST ANSWER

You're trying to execute /etc/passwd and send the output to cut. You want to redirect the contents of the file:

for user in `cut -f 1 -d : < $USERS`