0

I have rwo users User1 and User2.

I have this script1.sh inside User2 home folder:

#!/bin/bash

cd /home/user1 && ./script2.sh

that calls script2.sh:

#!/bin/bash

if [ 2 > 1 ]; then
echo TRUE!.
else
echo NOT TRUE!
fi

Now, when I execute script1 using user1, everything works. When I execute with user2 i get this error:

./script2.sh: line 3: 1: Permission denied

Saying I can't.. IF? If I write everything on the terminal, it also works. So my permissions:

-rwxrwxr-x 1 user2 group_with_both_users 149 Ago 19 02:41 script2.sh
-rwxr-xr-x 1 user2 group_with_both_users 60 Ago 19 01:38 script1.sh

I really have no clue of what is going on.

1
  • Do the directories have proper permissions?
    – muru
    Aug 19, 2014 at 5:57

2 Answers 2

5

The line

if [ 2 > 1 ]; then

causes the shell to try and open a file named 1 for writing. Read the section REDIRECTION in the bash man page for an explanation. Your user1 apparently is allowed to write to that file, and user2 isn't.

You were probably thinking of this:

if [ 2 -gt 1 ]; then

Which tests whether 2 is greater than 1, which is obviously true except for very large values of 1.

0

The following expressions are used with integers:
Table 27-3 (from tlcl's pdf book):

Integer Expressions:

Expression             Is True If...
integer1 -eq integer2 integer1 is equal to integer2.
integer1 -ne integer2 integer1 is not equal to integer2.
integer1 -le integer2 integer1 is less than or equal to integer2.
integer1 -lt integer2 integer1 is less than integer2.
integer1 -ge integer2 integer1 is greater than or equal to integer2.
integer1 -gt integer2 integer1 is greater than integer2.

So, You have to use -gt instead of > in if expression.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .