Help With A Unix Command

Discussion in 'macOS' started by rlm22b, Jun 18, 2009.

  1. rlm22b macrumors member

    rlm22b

    Joined:
    Mar 8, 2008
    Location:
    Indiana
    #1
    I recently decided that I wanted to learn more about Unix. I found this article and have been reading through it. It's pretty good thus far. I arrived at the part where they're discussing how to remove files and how you can customize terminal so that it prompts you before removal. I thought that would be good to have since I'm fairly new to Unix/Terminal. I inputted the command they gave but it will not work and I was wondering if anyone could help? Their discussion of the situation is below. Thanks in advance!

    I guess I should have said specifically which commands weren't working.

    I type:

    % echo "alias cp cp -i \\!\*" >> ~/.tcshrc
    % echo "alias mv mv -i \\!\*" >> ~/.tcshrc
    % echo "alias rm rm -i \\!\*" >> ~/.tcshrc

    and they are accepted with no errors but the changes never go into effect. I have opened new terminal windows and closed and reopened terminal.
     
  2. Koronis macrumors member

    Koronis

    Joined:
    Feb 16, 2009
    Location:
    Windsor,Ontario,Canada
    #2
    you should try logging out and then back in, that should make the system re-read any files with settings in them.
     
  3. belvdr macrumors 601

    Joined:
    Aug 15, 2005
    #3
    Don't put the % sign at the beginning. No need to restart/log out or anything similar. This is Unix, not Windows. ;)

    EDIT: Think I may be misreading the 2nd comment. So are the changes showing the .tcshrc or not? After rereading your post, I'm not sure if the changes aren't occuring in .tcshrc or if they aren't showing up for your commands.
     
  4. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #4
    Yes you'll need to log out and back in for the OS toy reread any config files
    BUT
    If you're using Leopard editing the .tcshrc file isn't going to affect anything. OS X hasn't used the tcsh shell in quite a while. Your changes should be made to the .bashrc file if anything.
     
  5. rlm22b thread starter macrumors member

    rlm22b

    Joined:
    Mar 8, 2008
    Location:
    Indiana
    #5
    Thank you all for the replies.

    I tried to logout and log back in but that didn't work. I didn't use the %.

    The changes are showing up in .tcshrc albeit one of the \'s before the ! isn't showing up for some reason.

    I am using Leopard. .bashrc is a config file also? The .tcshrc file was not present in my home directly before I edited it with the commands. Nor was the .bashrc file. I tried:

    % echo "alias cp cp -i \\!\*" >> ~/.bashrc

    as well but it didn't work either.

    I had an assigment for work to do on Matlab, which requires X11 to run. This was shot out as soon as the xterm window opened:

    [​IMG]

    Sorry I was too lazy to retype all of that and it wouldn't let me copy it. :)
     
  6. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #6
    Woo so many issues here..

    That's because the bash shell uses .profile to store aliases.

    Once you have the alias in the .profile, you can either open a new shell (which will inherit your alias) or source ~/.profile to re-read your .profile in your current shell. (or .bash_profile, but .profile is shorter. ;) )

    As noted before, you're not typing the % symbol are you? That was just to note that it was a tcsh shell. Bash shells prompts end with $.

    Alternately, you could just edit your .profile and add the alias in by hand.

    And finally, in the bash shell, alias are written thusly:

    alias shortcut="actual command"

    e.g.,

    alias lf="ls -laF"
     
  7. jw2002 macrumors 6502

    Joined:
    Feb 23, 2008
    #7
    Also, minor nit: in the case of the alias commands originally presented, you don't need to specify the token for the remaining command line arguments. In other words, the following, simpler alias command is sufficient:

    Code:
    % [b]alias rm rm -i[/b]
    You only need to add those other tokens when fancier things are being done, say an alias that performs one command that does one thing and then pipes to another.
     
  8. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #8
    Come on folks, this isn't that hard.

    Here is the command to use:

    echo "alias q=\"quota -g\"" >> ~/.bashrc

    The actual command line command would be:

    alias q="quota -g"

    But you have to use the "\" (escape character) to tell the system to not interpret the two middle quotes as closing the first quote.

    Once you have the new alias in the .bashrc (or .bash_profile) file, you use the "source" command to get the shell to re-read the file. For example:

    source .bashrc

    Now the "q" command will execute "quota -g".

    No need to log out or anything else....

    S-
     
  9. mslide macrumors 6502a

    Joined:
    Sep 17, 2007
    #9
    Hold on here folks, let's back up a minute for the OP:

    That stuff in your original posting mentions ~/.tschrc. 'tsch' is a unix 'shell'. One of many unix shells. By default, Linux and OSX (and many other modern Unix OS) use the 'bash' shell. That means, ~/.tschrc is not looked at unless you changed your shell (don't unless you know what you are doing). I don't recommend following any guides that use "tcsh" or "csh" as the syntax can be different than using bash.

    There are 2 configuration files you need to worry about when using bash:
    ~/.bashrc
    ~/.profile

    There's also ~/.bash_profile, but you don't need to use it.

    There is a difference in when one is read versus the other, but that is a more advanced topic. All you need to know now is that when you open up Terminal, ~/.profile is the file that is read and ~/.bashrc is NOT unless you force it to be read. There are other times when ~/.bashrc is read and not ~/.profile but you don't need to worry about that yet. If you want to learn more about this topic, try googling stuff about interactive shells vs non-interactive shells and login shells vs non-login shells. Or google "bashrc vs profile"

    So, all this echo "alias ..." stuff goes in ~/.profile. You can do what many do and that is have .profile source .bashrc, but that is a more advanced topic as you should know when one is read vs the other if you start doing that.

    So, put all of this alias stuff in your ~/.profile. If you change it, you have to re-read it. You can do this by either closing terminal and opening it back up or you can execute the following command:
    $ source ~/.profile

    The '$' is not typed. It represents your command prompt.

    Now, all this echo "blah blah" >> ~/.profile stuff will work, but I recommend you get familiar with a command line text editor and start editing files directly so you can get more familiar with what is in them. There are lots to choose from. 'nano' should be installed by default and it is very easy to use.
     
  10. rlm22b thread starter macrumors member

    rlm22b

    Joined:
    Mar 8, 2008
    Location:
    Indiana
    #10
    Thank you all so very much for all your help thus far!

    I entered:

    $ echo "alias rm rm -i \\!\*" >> ~/.profile

    No $ of course and the command was accepted.

    However it still does not seem to be working. I opened a new terminal window and I also did the 'source ~/.profile' command. When I did the source command the the output from X11(below) when I started Matlab yesterday came up. And now is appearing at the beginning of all of my new Terminal windows.

    -bash: alias: cp: not found
    -bash: alias: cp: not found
    -bash: alias: -i: not found
    -bash: alias: !*: not found
    -bash: alias: rm: not found
    -bash: alias: rm: not found
    -bash: alias: -i: not found
    -bash: alias: !*: not found

    Also, not sure if this is off topic. My IP address is showing up after a z and before ~ UserName$. What exactly does that mean? Or is it related to something I've done?
     
  11. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #11
    rlm22b,

    Did you read what I wrote?? The bash shell does not use this format to set aliases:

    alias q quota -g

    It uses:

    alias q="quota -g"

    Until you get that right, nothing is going to work.

    Look at my previous post again.

    S-
     
  12. rlm22b thread starter macrumors member

    rlm22b

    Joined:
    Mar 8, 2008
    Location:
    Indiana
    #12
    It works!!! I did:

    echo "alias rm=\"rm -i\"" >> ~/.profile

    like you said Sidewinder and it finally went through. Though I am a little uncertain as to what the \ and ''s do exactly. It got rid of the erratic output at the beginning of each terminal window too thankfully. Thank you all for taking the time to help. I really appreciate it.

    I guess my next task is to learn more about the different kinds of shells that msline mentioned.
     

Share This Page