Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is this going to be visible in the process listing if the below line is executed from a command line or a shell script

bash -c "echo $password"

or

i just need to do echo $password from within bash on a command line or inside bash shell script

is there any test i can do to check such visiblity. i was just trying this but i wasn't able to see it in the process listing with ps -ef | grep testscript

testscript:

i=0
while (( i < 100 ))
do
((i=i+1))
sleep 1
echo $$
echo hello
uname
done
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Just force it to use the builtin:

builtin echo foo

If echo is not a builtin, this will fail.

share|improve this answer
    
Thanks @Chris one doubt..is this going to be valid for linux only ? or will it work inside shells other than bash? –  munish May 6 '13 at 7:30
    
@munish builtin is not POSIX, but is supported in most modern shells (bash, zsh, most implementations of ksh). –  Chris Down May 6 '13 at 7:37

The arguments to a builtin will never show up in any ps output, because the builtin is not a separate program with its own command line. All modern shells (except some highly stripped-down configurations of BusyBox), including all bash versions, have echo built in.

Note that if you're calling bash -c "echo $password", then the password will show up for everyone to see, because it's embedded in the command that you run with bash. Calling a shell just to call its echo command is pointless, so hopefully you aren't doing that.

It's ok to put the password in an environment variable, if you need to pass it to a different process. Unlike command line arguments, environment variables are not exposed to other users under Linux and most other unices.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.