Hi aus9
... How about I change your -d test to something like this? ...
----- Snip -----
[ -d "$LOOP" ] || rm -rf /usr/local/bin/seatd* && cp $LOOP/seatd* /usr/local/bin
----- Snip -----
...
That doesn't look right. If the directory exists, you want to execute the
next 2 commands. That means it would look like this:
[ -d "$LOOP" ] && rm -rf /usr/local/bin/seatd* && cp $LOOP/seatd* /usr/local/binI'll demonstrate. We'll create a Loop variable, 3 file names, use
ls instead of
rmand
echo instead of
cp:
tc@E310:~/Test$ Loop="/home/tc/.local/bin"
tc@E310:~/Test$ touch x1 x2 x3
tc@E310:~/Test$ [ -d "$Loop" ] || ls x* && echo "Copy"
Copy
tc@E310:~/Test$ It skipped the first command and only executed the second command.
Lets try it the other way:
tc@E310:~/Test$ [ -d "$Loop" ] && ls x* && echo "Copy"
x1 x2 x3
Copy
tc@E310:~/Test$ It executed both commands.
Here's another thing to watch out for when chaining commands like this.
What happens if the first command fails:
tc@E310:~/Test$ [ -d "$Loop" ] && ls y* && echo "Copy"
ls: cannot access 'y*': No such file or directory
tc@E310:~/Test$ The
ls command fails so the
echo command never runs.
By the way, this happens if the directory does not exist:
tc@E310:~/Test$ Loop2="/home/tc/.local/bin2"
tc@E310:~/Test$ [ -d "$Loop2" ] || ls x* && echo "Copy"
x1 x2 x3
Copy
tc@E310:~/Test$ It executes both commands, which is the opposite of what you want.
I usually take the if [ TEST ]; then Commands; fi approach because it's
harder to mess up. On occasions I do chain commands, I first create test
cases like above using harmless ls and echo commands to make sure
I got it right.