Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

terminal prob

  • 13-06-2009 12:54AM
    #1
    Closed Accounts Posts: 2,653 ✭✭✭


    ls command in terminal returns this:

    -bash: ls: command not found

    what is the problem?

    thanks


«1

Comments

  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    Sounds like the PATH variable for the shell is messed up so it doesn't know where to look for the ls command.

    In the terminal type "echo $PATH" (without quotes) and hit enter. That will display the PATH variable.

    Here's the PATH variable for my system:
    /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    Your PATH variable may be different as I have the Developer tools and Macports installed on my system.

    You can edit the .profile file in the home directory to manually updated the PATH variable. The change should take effect the next time you login.

    Otherwise you can manually provide the path to the command, i.e. "/bin/ls" instead of "ls", to execute the command.


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    ok thanks

    but i have no idea what you meant

    this is what returned when i did that -

    /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:

    what does that mean?

    the bin/ls works :)


  • Closed Accounts Posts: 161 ✭✭pvik00


    ok thanks

    but i have no idea what you meant

    this is what returned when i did that -

    /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:

    what does that mean?

    the bin/ls works :)

    That means that your problem is what Talisman suggested. Something or someone misconfigured your environment scripts. You need to add those directories to your PATH that contain the most commonly used binaries, and remove the entries that don't. Do you at all have a /opt directory?
    Just follow his solution, but be aware that Terminal and xterm behave differently when it comes to environment settings.

    For the record, however, OS X these days sets PATH differently.
    It calls /etc/profile, that calls /usr/libexec/path_helper. The latter script sets $PATH from the list contained in /etc/paths.


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    Talisman wrote: »

    You can edit the .profile file in the home directory to manually updated the PATH variable. The change should take effect the next time you login.

    how do i edit it - edit it to what?

    sorry if they are stupid question, but i am confused


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    pvik00 wrote: »
    That means that your problem is what Talisman suggested. Something or someone misconfigured your environment scripts. You need to add those directories to your PATH that contain the most commonly used binaries, and remove the entries that don't. Do you at all have a /opt directory?
    Just follow his solution, but be aware that Terminal and xterm behave differently when it comes to environment settings.

    For the record, however, OS X these days sets PATH differently.
    It calls /etc/profile, that calls /usr/libexec/path_helper. The latter script sets $PATH from the list contained in /etc/paths.

    that is all i understood - yes it is a ''directory'' :confused:
    thanks


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    ok thanks

    but i have no idea what you meant

    this is what returned when i did that -

    /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:

    what does that mean?

    the bin/ls works :)
    Something messed up the PATH variable.

    When you type a command such as ls at the command line in the terminal window the OS looks in the directories specified in the PATH variable for the executable.

    In your case the OS is only looking in the following two locations:
    /opt/local/bin
    /opt/local/sbin


  • Closed Accounts Posts: 161 ✭✭pvik00


    that is all i understood - yes it is a ''directory'' :confused:
    thanks

    OK, but do you or do you not have it on your system?
    If you do, what's in it?


  • Closed Accounts Posts: 161 ✭✭pvik00


    how do i edit it - edit it to what?

    sorry if they are stupid question, but i am confused

    No worries.
    Just use any text editor on the system and edit it to look similar to what Talisman wrote earlier about how it generally looks.

    Just to understand how yours went wrong, can you paste your /etc/paths?


  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    how do i edit it - edit it to what?

    sorry if they are stupid question, but i am confused
    You need to add the missing locations to your PATH variable.

    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

    For detailed instructions on how to edit the .profile file to correct the issue follow this link: OS X: Change your PATH environment variable

    It's far more detailed than instructions that I could possibly post. :)


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    ok
    ill read through that and see whats what

    thanks


  • Advertisement
  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    pvik00 wrote: »
    No worries.
    Just use any text editor on the system and edit it to look similar to what Talisman wrote earlier about how it generally looks.

    Just to understand how yours went wrong, can you paste your /etc/paths?

    -bash: /etc/paths: Permission denied

    /opt

    contains -


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    ok

    open .profile - ''open .profile
    -bash: open: command not found''

    is there anyway to restore terminal to default settings without reinstalling - because this looks fairly fooked


  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    Don't let not having a valid PATH variable frustrate the **** out of you trying to edit a file from the command line - help is at hand! :)

    Download and install TextWrangler.

    Launch TextWrangler and in the main menu go to "File > Open Hidden..."

    Browse to your home directory and you'll see the elusive ".profile" file.

    In the "Enable" drop down menu select "All Files" - this will allow you to select ".profile" for editing.

    Once you have selected the file click "Open"

    Make your changes and save the file.

    Restart the system and you should be back in business.


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    thank you for your help

    ill download and see whats what now :)


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    okay

    i cant find .profile in textwrangler


  • Registered Users, Registered Users 2 Posts: 6,790 ✭✭✭cornbb


    Try bin/open ~/.profile -a TextWrangler.app in Terminal


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    bin/open ~/.profile -a TextWrangler.app
    -bash: bin/open: No such file or director


  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    okay

    i cant find .profile in textwrangler
    As a matter of interest do you see any of the hidden files in the home directory? I've attached a screen capture of some of the hidden files and folders that appear in the open hidden dialog on my computer for reference.

    If there's no .profile file you can always create your own - just be sure that it's in the home directory.

    For reference here is the default content of the .profile:
    ##
    # DELUXE-USR-LOCAL-BIN-INSERT
    # (do not remove this comment)
    ##
    echo $PATH | grep -q -s "/usr/local/bin"
    if [ $? -eq 1 ] ; then
        PATH=$PATH:/usr/local/bin
        export PATH
    fi
    


  • Closed Accounts Posts: 161 ✭✭pvik00


    bin/open ~/.profile -a TextWrangler.app
    -bash: bin/open: No such file or director

    A leading slash '/' is required:
    /bin/open ~/.profile

    It can also be /usr/bin/open, depending on your OS version.

    Still, the easiest is if you address this via /etc/paths.
    What is the current contents of that file?


  • Registered Users, Registered Users 2 Posts: 6,789 ✭✭✭Talisman


    I've had a few more thoughts about this.

    Can you run the following commands in the terminal shell:
    /bin/ls -al /etc/paths
    
    That will show you the timestamp of when the system paths file was last modified.

    Also:
    /bin/cat /etc/paths
    
    That command will show you the contents of the file if it exists

    The paths that appear in the /etc/paths file should be available to the logged in user by default unless a login script is messing things up.

    Can you look for these hidden files in the home folder:
    .bash_profile
    .bash_login
    .login

    One of these could be messing up your PATH variable if there's no .profile and creating a new .profile may achieve nothing if that is the case.


  • Advertisement
  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    ''defaults write com.apple.finder AppleShowAllFiles TRUE
    -bash: defaults: command not found''

    i couldnt see hidden files so i googles and that command doesnt work


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    ''/bin/open ~/.profile
    -bash: /bin/open: No such file or directory''

    ''/usr/bin/open
    Usage: open [-e] [-t] [-f] [-W] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames]
    Help: Open opens files from a shell.
    By default, opens each file using the default application for that file.
    If the file is in the form of a URL, the file will be opened as a URL.
    Options:
    -a Opens with the specified application.
    -b Opens with the specified application bundle identifier.
    -e Opens with TextEdit.
    -t Opens with default text editor.
    -f Reads input from standard input and opens with TextEdit.
    -W, --wait-apps Blocks until the used applications are closed (even if they were already running).
    -n, --new Open a new instance of the application even if one is already running.
    -g, --background Does not bring the application to the foreground.
    -h, --header Searches header file locations for headers matching the given filenames, and opens them.''

    okay - that did something. yay - havent the slighest what it means

    ''/etc/paths
    -bash: /etc/paths: Permission denied''

    i remember something about sudo - but that doesnt work here


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    /bin/ls -al /etc/paths
    -rw-r--r-- 1 root wheel 45 22 Sep 2008 /etc/paths

    on that note - this is a newer macbook as i got a replacement through insurance from apple so i got my files transfered so its not the same os as i had tiger this had leopard so in 2008 i didnt have this system

    and

    /bin/cat /etc/paths
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /usr/local/bin


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    Talisman wrote: »
    One of these could be messing up your PATH variable if there's no .profile and creating a new .profile may achieve nothing if that is the case.


    thanks for the help - both of ye


    i seem to be having problems finding any hidden files - but if that is not there is there anything i can do to restore it to defaults and fix the command terminal without reinstalling leopard


  • Closed Accounts Posts: 161 ✭✭pvik00


    thanks for the help - both of ye


    i seem to be having problems finding any hidden files - but if that is not there is there anything i can do to restore it to defaults and fix the command terminal without reinstalling leopard

    No worries.

    You don't necessarily have to have any of these hidden files if all the rest of your shell initialization scripts exist and are in order.
    In your case, it's either one of these scripts is misconfigured or you do have one of the .profle or .bash_profile files setting the unwanted values of PATH.

    Your /etc/paths looks OK.
    Can you paste the contents of /etc/profile and /usr/libexec/path_helper?

    By the way, what is the default shell your Terminal uses? Initialization scripts differ for different type of shell.
    Type
    echo $SHELL


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    /etc/profile and /usr/libexec/path_helper
    -bash: /etc/profile: Permission denied

    and

    echo $SHELL
    /bin/bash


  • Closed Accounts Posts: 161 ✭✭pvik00


    /etc/profile and /usr/libexec/path_helper
    -bash: /etc/profile: Permission denied

    and

    echo $SHELL
    /bin/bash

    You shouldn't run those scripts, you need to list the contents instead. This may hint us on where your environment is misconfigured.
    Use the cat command:

    cat /etc/profile

    and

    cat /usr/libexec/path_helper


  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    what do you mean dont run them but list the contents?


    cat /etc/profile
    -bash: cat: command not found

    and

    cat /usr/libexec/path_helper
    -bash: cat: command not found


  • Closed Accounts Posts: 161 ✭✭pvik00


    what do you mean dont run them but list the contents?


    cat /etc/profile
    -bash: cat: command not found

    and

    cat /usr/libexec/path_helper
    -bash: cat: command not found

    Exactly that.
    It seems that 'cat' is not on your path, either.
    Try /bin/cat, such as:

    /bin/cat /etc/profile

    /bin/cat /usr/libexec/path_helper


  • Advertisement
  • Closed Accounts Posts: 2,653 ✭✭✭conchubhar1


    /bin/cat /etc/profile
    # System-wide .profile for sh(1)

    if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    fi

    if [ "${BASH-no}" != "no" ]; then
    [ -r /etc/bashrc ] && . /etc/bashrc
    fi
    export PATH=/opt/local/bin:/opt/local/sbin:$PA TH
    export MANPATH=/opt/local/man:$MANPATH

    and

    /bin/cat /usr/libexec/path_helper
    #!/bin/sh
    #
    # Each line of the text files in /etc/paths are directories that should be
    # added to the current path. We source /etc/paths/default first, so that
    # the default paths (/usr/bin:/bin:/usr/sbin:/sbin) appear early in the path.
    #

    shopt -s extglob
    function read_path_dir () {
    DIR="$1"
    NEWPATH="$2"
    SEP=""
    IFS=$'\n'
    if [ -d "$DIR".d ]; then
    for f in "$DIR" "$DIR".d/* ; do
    if [ -f "$f" ]; then
    for p in $(< "$f") ; do
    "$NEWPATH" = *(*:)${p}*(:*) && continue
    [ ! -z "$NEWPATH" ] && SEP=":"
    NEWPATH="${NEWPATH}${SEP}${p}"
    done
    fi
    done
    fi
    echo $NEWPATH
    }

    P=`read_path_dir /etc/paths "$PATH"`
    MP=`read_path_dir /etc/manpaths "$MANPATH"`

    if [ "$1" == "-c" -o \( -z "$1" -a "${SHELL%csh}" != "$SHELL" \) ]; then
    echo setenv PATH \"$P\"\;
    echo setenv MANPATH \"$MP\"\;
    exit 0
    elif [ "$1" == "-s" -o -z "$1" ]; then
    echo PATH=\"$P\"\; export PATH;
    echo MANPATH=\"$MP\"\; export MANPATH;
    exit 0
    else
    echo "usage: path_helper [-c | -s]" 1>&2
    exit 1
    fi


    i have no idea what any of that means


Advertisement