jculkincys
asked on
Bash script security/robustness
I have finished writing a bash script and I want to provide it with a little more robustness and security - all suggestions are welcome.
One of the things that I want to ensure is that the commands that are run (ex. "echo") are always run from a certain location (ex: "/bin or /usr/bin") - I think can do this by setting the path in the script - does anyone else have any ideas?
Thanks
jculkincys
One of the things that I want to ensure is that the commands that are run (ex. "echo") are always run from a certain location (ex: "/bin or /usr/bin") - I think can do this by setting the path in the script - does anyone else have any ideas?
Thanks
jculkincys
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Nope. Full paths disable aliases.
/bin/echo need not be the same as "echo".
/bin/echo need not be the same as "echo".
> Nope. Full paths disable aliases.
hmm, nice shell ... which shell does that (for example for cd, [, set, ...)? Please test before posting ;-)
I said built-in commands, see http:#16485809
hmm, nice shell ... which shell does that (for example for cd, [, set, ...)? Please test before posting ;-)
I said built-in commands, see http:#16485809
ASKER
m1tk4 - or anyone else
can you explain what pushd does?
can you explain what pushd does?
pushd saves the current directory to the "stack" and changes current directory to the directory that is its argument
popd changes current directory to the last directory in the "stack" and removes the last entry in the "stack".
Example
# current directory = /home/somewhere
pushd /tmp
# current directory: /tmp, stack: /home/somewhere
pushd /var
# current directory: /var, stack: /tmp, /home/somewhere
popd
# current directory: /tmp, stack: /home/somewhere
popd
# current directory: /home/somewhere, we're back to where we started.
popd changes current directory to the last directory in the "stack" and removes the last entry in the "stack".
Example
# current directory = /home/somewhere
pushd /tmp
# current directory: /tmp, stack: /home/somewhere
pushd /var
# current directory: /var, stack: /tmp, /home/somewhere
popd
# current directory: /tmp, stack: /home/somewhere
popd
# current directory: /home/somewhere, we're back to where we started.
ASKER
Cool m1tk4 thanks
ok what is the verdict on full paths?
should I do "echo" or "/bin/echo"
ok what is the verdict on full paths?
should I do "echo" or "/bin/echo"
> should I do "echo" or "/bin/echo"
these are 2 different things, you need to check man-pages (shell and echo) which one you want to use
these are 2 different things, you need to check man-pages (shell and echo) which one you want to use
here is what is typically done in rcinit scripts:
ECHO="/bin/echo"
$ECHO "hello world"
$ECHO "hello hello"
and so on.
ECHO="/bin/echo"
$ECHO "hello world"
$ECHO "hello hello"
and so on.
ASKER
does anyone know how I could have pushd operate silently?
depends on yopur shell, csh syntax:
pushd>&/dev/null
pushd>&/dev/null
ASKER
I believe it has something to do with setting the pushdsilent variable
according to http://www.ss64.com/osx/pushd.html
but I can't seem to get it to work
according to http://www.ss64.com/osx/pushd.html
but I can't seem to get it to work
pushd and popd are shell built-in commands, only csh and tcsh support pushdsilent shell variables
.. and you're trapped by aliases (for built-in commands).