Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What is the best way to organise the sh/bash/python scripts you collect and write on your system?

share|improve this question

migrated from stackoverflow.com Nov 21 '09 at 16:20

This question came from our site for professional and enthusiast programmers.

12 Answers 12

up vote 6 down vote accepted

I have all such scripts in ~/bin which also is a svn working for all the scripts I frequently use on multiple computers. It also contains parts of my zsh configuration like aliases and environmental variables.

share|improve this answer

I put all my scripts (anything that is potentially platform independent) into ~/cmd and prepend that (and a bunch of other stuff) to PATH in my .zlogin and .bash_profile.

I use ~/bin for some hand-installed platform-specific binaries (or symlinks to such binaries).

Keeping the platform/machine-specific stuff out of ~/cmd makes it easier to copy it from machine to machine (I have mine in Git to provide history and transportation between machines).

share|improve this answer

I keep all of my development stuff under user\dev, which is symlinked to my dropbox folder, to keep everything backed up. (ok, I lied, most graphical stuff is in dev\..\graphics to reduce dropbox usage for things that don't need to be backed up as often)

Scripts stay in dev, and if I find myself using them often I'll alias something to them, rather than having everything in there on my path. ('alias' here referring to doskey, which I automated with a python script which I aliased to alias)

share|improve this answer

Currently I'm storing everything in a folder in my home directory, ~/sh. I have added it to the PATH in .bashrc (and .zshrc, since I use both.)

The flaw is that applications that are not started by a terminal, like the X server, do not pick up the modified value of PATH. I am then forced to prepend 'sh/' to the file name when I launch those scripts from the graphical interface.

share|improve this answer

Depends on the purpose of the script. I generally break mine down between one of two locations. Either ~/tools for serious stuff I reuse on a regular basis or ~/playground/[name of feature I'm toying with].

share|improve this answer

Most scripts I write are specific to a certain project, so I just leave them in the directory for that project. You don't have to add them to any PATHs, and it's easy to remember what they're for.

For global scripts on the other hand, a ~/sh directory sounds like a winner.

share|improve this answer

Much like everyone else here, I go with ~/bin for most scripts, and leave project specific things under ~/projects/whatever.

share|improve this answer

Under windows, you can set system-wide environment variables either for all the users or for a specific user.

This means that whenever a program starts it knows the environment variables you set. Of course, you can also set the environment variables from another process, such as CMD, and in this case only programs that are being started from this process will know those variables.

I don't know a way under Linux to set system-wide environment variables for specific users, but there is a way to set system-wide environment variables for all the users.

you can write the value you want in this file: /etc/environment

Values set in this file will be recognized by all the programs, for all the users.

You can do 'man pam_env' to get more information about the daemon that actually process this file.

Hope it helps,

Jonathan Orlev

share|improve this answer
    
The problem is, this is a system wide change. Only I and root have access to ~/sh; I would rather not mess with root's PATH as that might break system scripts. –  badp Sep 17 '08 at 9:23

I keep all my frequently used scripts in ~/scripts and have configured my /etc/profile to include that folder in my path for all users.

if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
        PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
        PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi

PATH="${PATH}:~/scripts"
share|improve this answer

What I do is this:

Have /home/myname/Scripts/

I put all my scripts there (classifies in directories based on their function/project). Now the best part is, the entire /home/myname/Scripts/ is version controlled (with SVN). This way, I can modify and still can look back at my changes.

for all the apps to recognize this, you can try adding the path to /etc/profile (for bash).

in /etc/profile, last line, add

export PATH=${PATH}:/home/myname/Scripts/
share|improve this answer

I have a ~code directory, with a subdirectory for every language I use, and in my .bashrc I have an instruction to source every one of them to my $PATH. For example:

dsm@localhost:~ $ cat .bashrc
...
export PATH="$(
    find /home/dsm/code -mindepth 1 -maxdepth 1 -type d -print\
        | perl -ne 'chomp; print"${_}:";'
)${PATH}" ;
...
dsm@localhost:~ $
share|improve this answer

For frequently used scripts I'm using ~/bin. You also may want to set something like

export PATH=/home/USER/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

in the ~/.bashrc file to add own scripts to executables search ath. But this method is very unsecure, and I recommend everyone always use full paths to all executables including ones in ~/bin. E.g. /usr/bin/sudo instead of just sudo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.