Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed a package s2cmd on my unix machine. It works fine when I run it from the folder it resides in, but it did not run from other locations so I set the PATH using the command export PATH=$PATH:/opt/bitnami/S3Tools/s3cmd-1.5.0-alpha1 there is a file s3cmd inside this folder which has to be executed.

The problem now is when I do a which s3cmd, I get the correct path as output but when I run it using, say sudo s3cmd, it says command not found. If I give the absolute path and try to run it, its runs from any location.

What am I doing wrong?

EDIT : I just noticed that there are 2 PATH variables with the same path. Is that causing the problem? If yes, how do I correct it?

$ set | grep PATH
    export PATH;                                                                                                                                                                       
    PATH="$(printf "%b" "$PATH"           | awk -v RS=: -v ORS=: '!($0 in a){a[$0];print}')";                                                                                          
    export PATH;                                                                                                                                                                       
    if printf "%b" "${PATH//:/ }" | GREP_OPTIONS="" \grep -vF "${rvm_bin_path}" > /dev/null 2>&1; then                                                                                 
        printf "%b" "export PATH ; PATH=\"${rvm_ruby_gem_home}/bin:${rvm_ruby_global_gems_path}/bin:${rvm_ruby_home}/bin:${rvm_bin_path}:\$PATH\"\n" > "$file_name";                   
        for variable in rvm_env_string rvm_path rvm_ruby_string rvm_gemset_name RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC MAGLEV_HOME RBXOPT;                                  
    export PATH;                                                                                                                                                                       
            \awk '/PATH/' < "$actual_file";                                                                                                                                            
            rvm_error "Neither md5 nor md5sum were found in the PATH";                                                                                                                 
            rvm_error "Neither md5 nor md5sum were found in the PATH";                                                                                                                 
    export PATH;                                                                                                                                                                       
    PATH="$(printf "%b" "$PATH"           | awk -v RS=: -v ORS=: "/${rvm_path//\//\/}/ {next} {print}")";                                                                              
    export PATH;                                                                                                                                                                       
    export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC;                                                                                                                          
                rvm_error "Neither sha256sum nor shasum found in the PATH";                                                                                                            
                rvm_error "Neither sha256sum nor shasum found in the PATH";                                                                                                            
        export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC;                                                                                                                      
        unset BUNDLE_PATH;                                                                                                                                                             
            new_path="$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$MY_RUBY_HOME/bin:${rvm_bin_path}:$(__rvm_remove_rvm_from_path ;printf "%b" "$PATH")";                              
            new_path="$GEM_HOME/bin:$MY_RUBY_HOME/bin:${rvm_bin_path}:$(__rvm_remove_rvm_from_path ;printf "%b" "$PATH")";                                                             
        export PATH="$new_path";                                                                                                                                                       
    unset GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC;                                                                                                                           
    new_path="$(__rvm_remove_rvm_from_path ; printf "%b" "$PATH"):${rvm_bin_path}";                                                                                                    
    COMPREPLY=($( eval PATH="$PATH:/sbin" $cmd 2>/dev/null |         awk '/^[^ \t]/ { print $1 }' ));                                                                                  
    if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then                                                                                                                            
    for i in ${CDPATH//:/'                                                                                                                                                             
    if [ "${INFOPATH: -1:1}" == ':' ]; then                                                                                                                                            
        if [ ${INFOPATH:+set} ]; then                                                                                                                                                  
    COMPREPLY=($( compgen -W "$( PATH="$PATH:/sbin" lsmod |         awk '{if (NR != 1) print $1}' )" -- "$1" ))                                                                        
    [ -z "$classpath" ] && classpath=$CLASSPATH;                                                                                                                                       
    local PATH="$PATH:/sbin:/usr/sbin";                                                                                                                                                
    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W         "$( PATH="$PATH:/sbin" lspci -n | awk '{print $3}')" -- "$cur" ))                                                               
    local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin;                                                                                                                                  
    COMPREPLY=("${COMPREPLY[@]}" $( compgen -W         "$( PATH="$PATH:/sbin" ifconfig -a |         sed -ne 's/.*addr:\([^[:space:]]*\).*/\1/p'             -ne 's/.*inet[[:space:]]\{1,\}\([^[:space:]]*\).*/\1/p' )"         -- "$cur" ))
    COMPREPLY=($( compgen -W         "$( PATH="$PATH:/sbin" sysctl -N -a 2>/dev/null )" -- "$cur" ));                                                                                  
    COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W         "$( PATH="$PATH:/sbin" lsusb | awk '{print $6}' )" -- "$cur" ))                                                                 
                        export rvm_ruby_gem_home GEM_HOME GEM_PATH;  
share|improve this question

migrated from Feb 27 '13 at 21:53

This question came from our site for professional and enthusiast programmers.

When you invoke sudo, the PATH is not normally reset. However it is possible to set an option which resets it. Check if env_reset is set in the sudoers file. – William Pursell Feb 27 '13 at 20:17
you'll have to give us an example of '2 PATH variables with the same path' Edit your question to include the output of set | grep PATH. Good luck. – shellter Feb 27 '13 at 20:21
Note that env_reset may or may not reset PATH, depending on how sudo was compiled. – William Pursell Feb 27 '13 at 20:31
If you’re going to talk about shell builtin commands like set, you need to say what shell you’re using (e.g., bash, csh, ksh, zsh, etc.) It looks like you’re running a shell where the set command outputs all variables and shell functions –– so you’re getting every line from every shell function that contains the string PATH, including some that set PATH. This is a red herring. If you distrust echo "$PATH", try env | grep "^PATH=". – Scott Feb 27 '13 at 22:53
You say, “It works fine when I run it from the folder it resides in.” Do you mean with sudo? What happens if you run it without sudo? … if you run it without sudo from another directory? (If you get a permissions error, that confirms that you set PATH correctly; if you get a “not found” error, that suggests that you didn’t.) Can you do sudo sh, sudo bash, sudo -s, or equivalent? If so, do that and then repeat the other steps (s3cmd, which s3cmd, echo "$PATH"). If your PATH variable has been replaced by a default, go back and try sudo -E to preserve the environment. – Scott Feb 27 '13 at 22:59

Your Answer


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