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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

terminal prob

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


    ls command in terminal returns this:

    -bash: ls: command not found

    what is the problem?

    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 6,289 ✭✭✭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,289 ✭✭✭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,289 ✭✭✭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,289 ✭✭✭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,289 ✭✭✭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,289 ✭✭✭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


  • Closed Accounts Posts: 161 ✭✭pvik00


    /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

    No worries man, I can now see what the problem is.

    /etc/profile is misconfigured, the last two lines in particular are not normally there after OS X installation. You may or may not need these entries depending on what you have under /opt, which is also not part of the default os installation.

    These are the lines I'm talking about:
    export PATH=/opt/local/bin:/opt/local/sbin:$PA TH
    export MANPATH=/opt/local/man:$MANPATH

    You have more then one way of fixing this issue but for now let's concentrate on the simplest one.
    Since I have no idea what or who the hell has put these entries into your config, I'll assume that it was some installer and we'll leave it in peace.

    Create a backup copy of /etc/profile and use any text editor to fix the typo on this line:

    export PATH=/opt/local/bin:/opt/local/sbin:$PA TH

    it should read

    export PATH=/opt/local/bin:/opt/local/sbin:$PATH

    You need to save the changes and exit the terminal. The changes above will set the appropriate directories (system binaries) for $PATH, leaving the extra unharmed.


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


    what do i do with the text file - what do i save it as and where?

    do i edit it in the terminal or in textedit for example?



    do i leave the original?



    thanks!


  • Closed Accounts Posts: 161 ✭✭pvik00


    what do i do with the text file - what do i save it as and where?

    do i edit it in the terminal or in textedit for example?



    do i leave the original?



    thanks!

    You can use any text editor you like. Since you said you don't understand shell programming, it's best if you create a backup copy.

    The simplest is to use the Terminal for both operations.

    copy (sudo will prompt for your admin password. just type it, there's no local echo):
    /usr/bin/sudo /bin/cp -p /etc/profile /etc/profile.old


    edit:
    /usr/bin/sudo /usr/bin/vi /etc/profile

    then navigate to the gap at $PA TH, at the end of the file, and once the cursor is on the gap, press x.
    Then press ESC :wq (sequentially, not together) and hit ENTER.
    If you're not comfortable with vi just use any other text editor.


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


    sudo
    -bash: sudo: command not found


    do i need sudo?


  • Closed Accounts Posts: 161 ✭✭pvik00


    sudo
    -bash: sudo: command not found


    do i need sudo?

    root is the owner of /etc/profile, so you either use sudo or authenticate as root using su -

    Since your path is messed up, you need to use the full path for all commands, type them _exactly_ as I wrote them above. sudo is in /usr/bin


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


    ~
    W10: Warning: Changing a readonly file
    E325: ATTENTION
    Found a swap file by the name "/private/etc/.profile.swp"
    owned by: root dated: Tue Jun 30 11:49:07 2009
    file name: /private/etc/profile
    modified: YES
    user name: root host name: bobs-macbook-1.local
    process ID: 1138
    While opening file "/private/etc/profile"
    dated: Sat Jun 6 06:34:48 2009

    (1) Another program may be editing the same file.
    If this is the case, be careful not to end up with two
    different instances of the same file when making changes.
    Quit, or continue with caution.

    (2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r /private/etc/profile"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file "/private/etc/.profile.swp"
    to avoid this message.

    Press ENTER or type command to continue

    # 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:$PATH
    export MANPATH=/opt/local/man:$MANPATH
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~


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


    pvik00 wrote: »
    Then press ESC :wq (sequentially, not together) and hit ENTER.
    If you're not comfortable with vi just use any other text editor.


    when do i press esc?

    where do i type :wq?


    ''E45: 'readonly' option is set (add ! to override)
    ''

    right so i added the exclamation mark

    ''# 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:$PATH
    export MANPATH=/opt/local/man:$MANPATH
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    "/etc/profile" [readonly] 11L, 277C''

    no scratch that - things seem to work now

    thanks!!!!


  • Closed Accounts Posts: 161 ✭✭pvik00


    cool stuff.


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


    deriously thanks very very much

    to you and all who helped
    :)


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


    Great to see you're finally sorted.


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


    indeed


    i am very greatful for all the help i received here - than you all very much


    it took me long to grasp it here where i was being spoonfed - imagine how long it would have taken me on my own if i had ever gotten it at all
    :D


Advertisement