using scripts in unix

Posted:
in macOS edited January 2014
if I have some unix scripts that I was gonig to use, where do I put them on my Mac, like some alias's that I have written.

Comments

  • Reply 1 of 8
    rara Posts: 623member
    You can put them anywhere, provided their location shows up in your $PATH.
  • Reply 2 of 8
    idunnoidunno Posts: 645member
    Quote:

    Originally posted by Ra

    You can put them anywhere, provided their location shows up in your $PATH.



    Cool, I just didn't know if there was a dedicated Scripts folder for this sort of thing.
  • Reply 3 of 8
    lundylundy Posts: 4,466member
    Quote:

    Originally posted by iDunno

    Cool, I just didn't know if there was a dedicated Scripts folder for this sort of thing.



    Bash shell aliases go in the ~/.bash_profile file.



    If you mean actual scripts, that you want treated as commands, you can put them in /usr/local/bin , and THEN add this to the above-mentioned .bash_profile file:



    PATH=$PATH:/usr/local/bin
  • Reply 4 of 8
    idunnoidunno Posts: 645member
    Quote:

    Originally posted by lundy

    Bash shell aliases go in the ~/.bash_profile file.



    If you mean actual scripts, that you want treated as commands, you can put them in /usr/local/bin , and THEN add this to the above-mentioned .bash_profile file:



    PATH=$PATH:/usr/local/bin




    Do I just use textedit to edit the .bash_profile file?



    In linux I have my .userchsrc where I put all my alias', is this the same as the .bash_profile?



    Sorry if these are really simple stupid questions.
  • Reply 5 of 8
    lundylundy Posts: 4,466member
    Quote:

    Originally posted by iDunno

    Do I just use textedit to edit the .bash_profile file?



    No, because it has a dot prefix and thus isn't visible in the Finder. Other text files, however, can be edited with TextEdit - just have to choose "Make Plain Text" in TextEdit before saving the file, otherwise it will save as RTF and BSD will not read it correctly.



    To edit .bash_profile, just use one of the BSD text editors: there are vi, emacs, pico and nano, and probably others.



    example:



    cd /

    sudo pico .bash_profile



    (no mouse allowed - use arrow keys to make your edits and then hit control-o to write out, hit Return to confirm, and then control-X to exit pico).

    Quote:

    In linux I have my .userchsrc where I put all my alias', is this the same as the .bash_profile?



    Thing is, I don't know Linux, but if you are using the bash shell (default in Panther and TIger), then .bash_profile is one place where you can put settings like aliases and settings that you want the shell to read when it launches. When you launch Terminal, you know you have the bash shell as its prompt character is the dollar sign.



    It's probably exactly the same thing - a file that the shell reads on launch to configure itself. I have my aliases there and they work fine.



    You can switch to csh or tcsh if you want -- they have different config files and I always have to look those things up.
  • Reply 6 of 8
    gene cleangene clean Posts: 3,481member
    Linux does use bash (Bourne Again Shell).
  • Reply 7 of 8
    There are actually two files, .bash_profile and .bashrc, both in your home directory. The former is run when you log in, the second every time you start a new shell. (So the short answer is that you put you aliases in .bash_profile.) Editing these will only affect you. There are similar files (probably in /etc) that affect all users.



    Other shells use slightly different conventions. For example your Linux box looks like it's using the C Shell (or maybe tcsh). You can get your Mac to use that instead too if you prefer (I think it's in user preferences but don't quote me on that!).



    BTW, try something like TextWrangler if you don't fancy the command-line/Unix text editors.



    --> Stephen
  • Reply 8 of 8
    idunnoidunno Posts: 645member
    thanks guys, I'll let you know how I go.
Sign In or Register to comment.