Terminal not showing working directory

Discussion in 'OS X Yosemite (10.10)' started by yollo, Nov 21, 2014.

  1. yollo, Nov 21, 2014
    Last edited: Dec 17, 2014

    yollo macrumors newbie

    Joined:
    Sep 17, 2014
    #1
    Hi!

    When I work in my Terminal it just shows -bash-3.2$. If i write cd directory it still only shows -bash-3.2$.

    Why is it not showing for what directory I'm in?

    Thanks in advance everyone!

    Edit:
    How can I get it to look like it does by default?
    Like this:
    Last login: Wed Dec 17 09:45:55 on console
    My-MacBook:~ user$

    Also, certain commands does not work, like ping etc..

    Rgs,
    Yollo
     
  2. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #2
    Read the bash man page, namely the part about INVOCATION.

    "When bash is invoked as an interactive login shell, or as a non-inter-
    active shell with the --login option, it first reads and executes com-
    mands from the file /etc/profile, if that file exists. After reading
    that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
    in that order, and reads and executes commands from the first one that
    exists and is readable. The --noprofile option may be used when the
    shell is started to inhibit this behavior."

    By default, the login shell runs /etc/profile which calls /etc/bashrc, which is where the prompt gets setup.
     
  3. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #3
    Hi!
    How can I get it to look like it does by default?
    Like this:
    Last login: Wed Dec 17 09:45:55 on console
    My-MacBook:~ user$


    Also, certain commands does not work, like ping etc.. I have no idea of what I've done.. :eek:
     
  4. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #4
    Check for the following files. The first three by default don't exist, those are for user specific changes. The second two are for the default shell settings, which sounds like what you want.

    For me running completely unmodified the output looks something like this.

    hostname:~ user$ ls -l .bash_profle .bash_login .profile
    ls: .bash_login: No such file or directory
    ls: .bash_profle: No such file or directory
    ls: .profile: No such file or directory

    hostname:~ user$ ls -l /etc/profile /etc/bashrc
    -r--r--r-- 1 root wheel 745 Sep 26 19:03 /etc/bashrc
    -r--r--r-- 1 root wheel 189 Sep 26 19:03 /etc/profile

    The reason some commands fail for you is probably that your path ($PATH) is fouled up, solving the profile setup will most likely also solve that. Note the following;

    hostname:~ user$ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

    hostname:~ user$ which ping
    /sbin/ping
     
  5. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #5
    It looks like this for me:
    -bash-3.2$ ls -l .bash_profle .bash_login .profile
    ls: .bash_login: No such file or directory
    ls: .bash_profle: No such file or directory
    ls: .profile: No such file or directory
    -bash-3.2$ ls -l /etc/profile /etc/bashrc
    -r--r--r-- 1 root wheel 745 Sep 27 04:03 /etc/bashrc
    -rw-r--r-- 1 niklasandersson staff 581 Nov 23 12:46 /etc/profile
    -bash-3.2$ echo $PATH
    /usr/bin:/bin
    -bash-3.2$ which ping
    -bash-3.2$
     
  6. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #6
    Looks to me like /etc/profile has been changed. I'd restore the original.
     
  7. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #7
    How can I do that..?
     
  8. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #8
    This is the content of the default file. Just create a text file with it and copy it to /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
     
  9. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #9
    I still get this when starting
    Last login: Thu Dec 18 09:11:26 on ttys000
    -bash: {rtf1ansiansicpg1252cocoartf1343cocoasubrtf160: command not found
    -bash: /etc/profile: line 2: syntax error near unexpected token `}'
    -bash: /etc/profile: line 2: `{\fonttbl\f0\fnil\fcharset0 Verdana;}'
    -bash-3.2$

    and ping does not work..
     
  10. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #10
    Are sure its plain text? You can use TextEdit to make plain text. You can check as follows;

    hostname:~ user$ 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
     
  11. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #11
    Oh, my bad. Now it is plain text and looks like this:
    Last login: Thu Dec 18 09:28:15 on ttys000
    -bash: 
: command not found
    -bash: 
: command not found
    -bash-3.2$


    Could it perhaps be the bashrc file?
    Also I can ping now at least! But i still want to get rid of the -bash-3.2$ and get it like you have it.
     
  12. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #12
    Double check the files owner and protection. Should be the same size as mine, 745 and 189.

    hostname:~ user$ ls -l /etc/profile /etc/bashrc
    -r--r--r-- 1 root wheel 745 Sep 29 18:54 /etc/bashrc
    -r--r--r-- 1 root wheel 189 Sep 29 18:54 /etc/profile

    You can test it by executing the following.

    hostname:~ user$ bash -x
    bash-3.2$ source /etc/profile

    -- Check the output here --
     
  13. NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #13
    Try running from the Terminal window:

    Code:
    bash -lv
    That should dump a transcript of the various dot files being run and their actions. What are the results from that?
     
  14. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #14
    This is even a better idea, starting as login (-l). Note that "bash -lv" is verbose, shows the commands run. You can do something similar with "bash -lx", which is trace output.
     
  15. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #15
    Sorry for my late reply, I have been on vacation!

    The output:
    -bash-3.2$ bash -lv
    # System-wide .profile for sh(1)

    bash: 
: command not found
    if [ -x /usr/libexec/path_helper ]; then
    eval `/usr/libexec/path_helper -s`
    fi
    /usr/libexec/path_helper -s
    PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"; export PATH;

    bash: 
: command not found
    if [ “${BASH-no}” != “no” ]; then
    [ -r /etc/barshrc ] && . /etc/bashrc
    fi
    bash-3.2$
     
  16. joedec, Jan 5, 2015
    Last edited: Jan 5, 2015

    joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #16
    Welcome back, what's this look like on your machine?

    $ which bash
    /bin/bash

    $ ls -l /bin/bash
    -r-xr-xr-x 1 root wheel 628736 Sep 26 19:03 /bin/bash

    Check the System Preferences/Users & Groups/Advanced Options and make sure your Login Shell is set to /bin/bash. BTW, an easier way to check login shell, from the shell, use the command `finger $USER`, but since your shell is broken ;=)

    There's also a setting in Terminal Preferences/Settings/Shell "Run command" most likely its empty.
     
  17. yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #17

    Hi again, here is the requested info!

    -bash-3.2$ which bash
    /bin/bash

    bash-3.2$ ls -l /bin/bash
    -r-xr-xr-x 1 root wheel 628736 Sep 27 04:03 /bin/bash

    Yes, my login shell under System Preferences/Users & Groups/Advanced Options it is set to /bin/bash....

    It says "Default login shell" under terminal preferences.
     
  18. NoBoMac, Jan 14, 2015
    Last edited: Jan 14, 2015

    NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #18
    Odd. Interpreting blank lines as commands from the looks of things. And never ran the /etc/bashrc since $BASH environment variable is defaulting to "no"

    Code:
    bash: 
: command not found
    if [ “${BASH-no}” != “no” ]; then
    [ -r /etc/barshrc ] && . /etc/bashrc
    fi
    So, first, do this from a Terminal window:

    Code:
    set | grep BASH
    printenv | grep SHELL
    To see what the variables are set to.

    From Settings > Users & Groups, unlock that panel with the admin login/passwd.Then, CMD-right-click on your user account entry to get the "Advanced Options" menu pick. Will get a screen like below. Make sure default shell is bash. If not, select from the dropdown list, save, reboot, as per instructions at top of window.
     

    Attached Files:

  19. yollo, Jan 14, 2015
    Last edited by a moderator: Jan 14, 2015

    yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #19
    Hi! Thanks for your reply.
    Is this the right info?

    Code:
    -bash-3.2$ set | grep BASH
    BASH=/bin/bash
    BASH_ARGC=()
    BASH_ARGV=()
    BASH_LINENO=()
    BASH_SOURCE=()
    BASH_VERSINFO=([0]="3" [1]="2" [2]="53" [3]="1" [4]="release" [5]="x86_64-apple-darwin14")
    BASH_VERSION='3.2.53(1)-release'
    -bash-3.2$ printenv | grep SHELL
    SHELL=/bin/bash
    Yes, I checked that in my last reply to Joedec and it looks like that..
     
  20. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #20
    Maybe there's something non-printing on those lines, so they aren't completely blank.


    The OP should post the output of this command, in CODE tags:
    Code:
    hexdump -C /etc/profile

    I made an example that illustrates the problem. I edited the 0x01 into the file using the Hex Fiend app.

    Here's the hexdump of the script:
    Code:
    00000000  23 21 2f 62 69 6e 2f 62  61 73 68 0a 65 63 68 6f  |#!/bin/bash.echo|
    00000010  20 22 20 2d 2d 20 53 74  61 72 74 22 0a 01 0a 65  | " -- Start"...e|
    00000020  63 68 6f 20 22 20 2d 2d  20 45 6e 64 22 0a        |cho " -- End".|
    0000002e
    
    The 01 is between the two 0a characters near the end of the 2nd line.

    When I run this script (which is named "burp") I get this output:
    Code:
     -- Start
    ./burp: line 3: : command not found
     -- End
    

    Finally, I suggest looking at the IFS shell variable.
     
  21. NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #21
    My thinking as well. Was going to suggest OP reenter the file, but to use something like vi or REALLY make sure TextEdit is set for text vs rtf.

    If OP does not have a hex/octal dump tool, vi can work in a pinch. From Terminal:

    Code:
    vi /etc/profile
    Then in vi, type:

    Code:
    :set list
    That will display non-printing character.

    Code:
    :set nolist
    to go back to normal.

    Good call on IFS: forgot about that one.
     
  22. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #22
    TextEdit could be set for plain text, but the charset it's writing the file in might not be acceptable for bash. Or there could be erroneous characters in the text, such as CRs (0x0d) or non-breaking space (0xa0). Once we see what's in the file we can try working out how it got there.

    I'm fairly sure hexdump is still installed as one of the default command-line tools. If not, we'll find out when he tries the command I posted.
     
  23. yollo, Jan 17, 2015
    Last edited by a moderator: Jan 17, 2015

    yollo thread starter macrumors newbie

    Joined:
    Sep 17, 2014
    #23
    Hi!

    Here comes the output of the first command:
    Code:
    -bash-3.2$ hexdump -C /etc/profile
    00000000  23 20 53 79 73 74 65 6d  2d 77 69 64 65 20 2e 70  |# System-wide .p|
    00000010  72 6f 66 69 6c 65 20 66  6f 72 20 73 68 28 31 29  |rofile for sh(1)|
    00000020  0a e2 80 a8 0a 69 66 20  5b 20 2d 78 20 2f 75 73  |.....if [ -x /us|
    00000030  72 2f 6c 69 62 65 78 65  63 2f 70 61 74 68 5f 68  |r/libexec/path_h|
    00000040  65 6c 70 65 72 20 5d 3b  20 74 68 65 6e 0a 65 76  |elper ]; then.ev|
    00000050  61 6c 20 60 2f 75 73 72  2f 6c 69 62 65 78 65 63  |al `/usr/libexec|
    00000060  2f 70 61 74 68 5f 68 65  6c 70 65 72 20 2d 73 60  |/path_helper -s`|
    00000070  0a 66 69 0a e2 80 a8 0a  69 66 20 5b 20 e2 80 9c  |.fi.....if [ ...|
    00000080  24 7b 42 41 53 48 2d 6e  6f 7d e2 80 9d 20 21 3d  |${BASH-no}... !=|
    00000090  20 e2 80 9c 6e 6f e2 80  9d 20 5d 3b 20 74 68 65  | ...no... ]; the|
    000000a0  6e 0a 5b 20 2d 72 20 2f  65 74 63 2f 62 61 72 73  |n.[ -r /etc/bars|
    000000b0  68 72 63 20 5d 20 26 26  20 2e 20 2f 65 74 63 2f  |hrc ] && . /etc/|
    000000c0  62 61 73 68 72 63 0a 66  69 0a                    |bashrc.fi.|
    000000ca
     
  24. NoBoMac macrumors 6502a

    Joined:
    Jul 1, 2014
    #24
    Yep. Full of incompatible characters in there.

    Where there are multiple "." strung together are the problem places. The hex values of the sequence starts with hex characters e2 and 80, and then followed by one other hex char. 0a is a line feed, so those are ok.

    Will need to delete out these non-printing characters and or reinput the text.

    A "clean" dump of the profile file looks like:

    Code:
    00000000  23 20 53 79 73 74 65 6d  2d 77 69 64 65 20 2e 70  |# System-wide .p|
    00000010  72 6f 66 69 6c 65 20 66  6f 72 20 73 68 28 31 29  |rofile for sh(1)|
    00000020  0a 0a 69 66 20 5b 20 2d  78 20 2f 75 73 72 2f 6c  |..if [ -x /usr/l|
    00000030  69 62 65 78 65 63 2f 70  61 74 68 5f 68 65 6c 70  |ibexec/path_help|
    00000040  65 72 20 5d 3b 20 74 68  65 6e 0a 09 65 76 61 6c  |er ]; then..eval|
    00000050  20 60 2f 75 73 72 2f 6c  69 62 65 78 65 63 2f 70  | `/usr/libexec/p|
    00000060  61 74 68 5f 68 65 6c 70  65 72 20 2d 73 60 0a 66  |ath_helper -s`.f|
    00000070  69 0a 0a 69 66 20 5b 20  22 24 7b 42 41 53 48 2d  |i..if [ "${BASH-|
    00000080  6e 6f 7d 22 20 21 3d 20  22 6e 6f 22 20 5d 3b 20  |no}" != "no" ]; |
    00000090  74 68 65 6e 0a 09 5b 20  2d 72 20 2f 65 74 63 2f  |then..[ -r /etc/|
    000000a0  62 61 73 68 72 63 20 5d  20 26 26 20 2e 20 2f 65  |bashrc ] && . /e|
    000000b0  74 63 2f 62 61 73 68 72  63 0a 66 69 0a           |tc/bashrc.fi.|
    000000bd
    
     
  25. joedec macrumors 6502

    joedec

    Joined:
    Jul 25, 2014
    Location:
    Cupertino
    #25
    Snag a copy of Textwrangler if vi is too much, free and really nice for all things text on a Mac.

    Or as I said early on, restore the file from Time Machine. It hasn't changed in a long time, you can even get a copy from 10.9, they're identical.
     

Share This Page