Tag Info

Hot answers tagged

68

PATH=$PATH:~/opt/bin PATH=~/opt/bin:$PATH depending on whether you want to add ~/opt/bin at the end (to be searched after all other directories, in case there is a program by the same name in multiple directories) or at the beginning (to be searched before all other directories). You don't need export if the variable is already in the environment: any ...


20

Either way works, but they don't do the same thing: the elements of PATHare checked left to right. In your first example, executables in ~/opt/bin will have precedence over those installed, for example, in /usr/bin, which may or may not be what you want. In particular, from a safety point of view, it is dangerous to add paths to the front, because if ...


15

The organization of configuration files is much less uniform than your questions seem to imply. There is no "class", there is no "hierarchy", and there is no global "configuration czar" nor committee that decrees a common syntax or other nice clean generalizations like the ones you are seeking. There is only a multitude of separate applications like R, ...


14

Grepping around in /etc turned up a link that Googling did not. It turns out you can control this in the file /etc/fstab. Just add a line that says none / cygdrive binary 0 0 and the problem should be fixed. No more kludgey fixes in .bashrc, and no messed-up $PATH.


14

alias without parameter outputs the definitions of currently defined aliases. declare -f outputs the definitions of currently defined functions. export -p outputs the definitions of currently defined variables. All those commands output definitions ready to be reused, you can redirect their outputs directly to a new ~/.bashrc. All lists will contain a ...


13

I have a handy bash function called calc: calc () { bc -l <<< "$@" } Example usage: $ calc 65320/670 97.49253731343283582089 $ calc 65320*670 43764400 You can change this to suit yourself. For example: divide() { bc -l <<< "$1/$2" } Note: <<< is a here string which is fed into the stdin of bc. You don't need to ...


11

You only need export for variables that should be "seen" by other programs which you launch in the shell, while the ones that are only used inside the shell itself don't need to be exported. This is what the man page says: The supplied names are marked for automatic export to the environā€ ment of subsequently executed commands. If the -f option is ...


11

Aliases ls is a command, l and la are most likely aliases which make use of the command ls. If you run the command alias you can find all the aliases on your system. $ alias | grep -E ' l=| la=' This will return all the aliases that match the pattern l=... or la=.... Debugging it further You can also use the command type to see how a particular command ...


10

I would look in /etc/profile.d/ for the offending alias. You could also do the following to find it: grep -r '^alias COMMAND' /etc This will recursively grep through files looking for a line beginning with alias COMMAND. If all else fails, put this at the end of your ~/.bashrc unalias COMMAND


10

I'm not going to exactly answer your question, but maybe give you an alternate solution to your problem. If I understand correctly you're concerned about mistakes you could make by typing, e.g., !rm if it happened that the previous rm command in history removes something you'd like to keep. In this case, a nice bash option is histverify. If you shopt -s ...


8

There's a few things you can try: use bash -v to see what lines are being read during shell startup use bash -x to see what commands are being run during shell startup run with only one startup file bash -v The -v option makes bash print each line from every script file it reads as it reads it. Start by running bash -i -v >bash-i.out 2>&1 ...


8

To detect an SSH session, use $SSH_CLIENT. To distinguish between local and remote sessions, there are two possible approaches: client-side or server-side. On the server side, compare $SSH_CLIENT with the local IP address or routing table; this'll usually tell you whether the connection is from the LAN. On the client side, you may want to put ForwardX11 ...


8

A shell is the generic name for any program that gives you a text-interface to interact with the computer. You type a command and the output is shown on screen. Many shells have scripting abilities: Put multiple commands in a script and the shell executes them as if they were typed from the keyboard. Most shells offer additional programming constructs that ...


8

You can put it in your .bash_profile, which gets executed everytime you log in. Or if it is an alias for a long command, you can put this in your .bash_aliases file under your home directory: alias short_version="very long command here"


8

. is the Bourne and POSIX shell command while source is the C-Shell command. Some Bourne-shell derivatives like bash, zsh and most implementations of ksh also have a source command which is generally an alias for . though for ksh with differences. For bash and zsh, . and source behave the same, but their behavior is affected by whether they run in POSIX ...


7

Not only is it possible, some systems set up new accounts with both. This allows the same skeleton setup to be used whichever shell the user gets. The purpose of the two file is the same, but they belong to two different shell families. The syntax of the shell scripts for the two shells is very different so different scripts are required. With a bit of ...


7

You could ignore the builtin history mechanism and abuse $PROMPT_COMMAND to write history any way you wanted. Some people keep a directory of history files, one for each shell/date/hostname, etc. Approx something like this: prompt_cmd() { echo "$_" >> $HOME/.my_history_file_$HOSTNAME } PROMPT_COMMAND=prompt_cmd obviously embellish with dates, ...


7

You could do something like: fixhist() { local cmd histnum cmd=$(HISTTIMEFORMAT=/ history 1) histnum=$((${cmd%%[*/]*})) cmd=${cmd#*/} # remove the histnum case $cmd in (rm\ *|mv\ *|...) history -d "$histnum" # delete history -s "#$cmd" # add back with a # esac } PROMPT_COMMAND=fixhist The idea being that before each ...


7

Why would it source it? You are not running true bash: $ echo $SHELL /bin/sh In most modern systems sh is a symlink to a basic shell. On my Debian for example: $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Aug 1 2012 /bin/sh -> dash In your case, sh is a link to bash but, as explained in man bash: If bash is invoked with the name sh, it tries ...


7

You can add a file to the system's /etc/profiile.d directory that includes a if/then statement for each of the users that you want to run the virtualenv for. Example Say I create a file like this, /etc/profile.d/me.sh. if [ "$USER" == "saml" ]; then touch /tmp/samsfile fi Make it executable: $ chmod +x /etc/profile.d/me.sh And then login as saml, ...


6

Guandalino, I'm confused by question 2. If you say PATH=~/opt/bin that's all that will be in your PATH. PATH is just an environment variable, and if you want to add to the PATH, you have to rebuild the variable with exactly the contents you want. That is, what you give as an example to question 2 is exactly what you want to do, unless I'm totally ...


6

As your first question, there's no way to list the conflicts, since bash use a hash table internally, it only records the last override. To find out if a command is an alias, use alias ls in your case, if it tells you something like "not found" then it's not an alias, otherwise it is. To launch original function disregarding the alias, prefix a slash, e.g ...


6

You can use the command type to see if the executable is present on your box: if [ -n "$(type -P tmux)" ]; then ...tmux is installed... else ...tmux isn't installed... fi I've often used this code snippet to do it: $ [ -n $(type -P tmux) ] && echo "installed" || echo "not installed" installed I can fake it out using the alternative ...


6

.bashrc scripts are only run by bash itself. They're not free-standing, and they're not intended to be executed by the system. (In fact, they're generally not marked executable, and, as you say, they don't have a shebang line.) Such scripts are intended to be sourced, since they generally do things like change environment variables ($PATH, for example), ...


6

.bashrc and .bash_profile are NOT scripts. They're configuration file which get sourced every time bash is executed in one of 2 ways: interactive login The INVOCATION section of the bash man page is what's relevent. A login shell is one whose first character of argument zero is a -, or one started with the --login option. An interactive shell ...


6

Yes. You have three main options: Symlink ~/.bashrc, mv ~/.bashrc ~/blah && ln -s ~/blah/.bashrc ~/.bashrc source the new file from ~/.bashrc, mv ~/.bashrc ~/blah && cat > ~/.bashrc << 'EOF' . ~/blah/.bashrc EOF or launch bash with --rcfile. mv ~/.bashrc ~/blah bash --rcfile ~/blah/.bashrc


6

The only reliable way to write scripts that support different operating systems is to only use features that are defined by POSIX. For things like your personal shell configurations, you can use hacks that fit your specific use case. Something like the following is ugly, but will accomplish the goal. if ls --version 2>/dev/null | grep -q 'coreutils'; ...


6

No, there isn't. Yes, this is a design defect. Use the following content in ~/.bash_profile: if [ -e ~/.profile ]; then . ~/.profile; fi if [[ -e ~/.bashrc && $- = *i* ]]; then . ~/.bashrc; fi Beware that bash has an even weirder quirk: when it is a non-interactive login shell and the parent process is rshd or sshd, bash sources ~/.bashrc (but ...


5

Yes, but it's the worst thing you can do. There are different users with different permissions in your OS. And that is on purpose. Giving root permissions to your user permanently will compromise the security of the system. (Remember Windows 9x and all the viruses ?) Executing a command with sudo wont need any of your customization stuff I guess, unless you ...


5

Change it to: if [ -z "$STARTED_SCREEN" ] && [ -n "$SSH_TTY" ] then case $- in (*i*) STARTED_SCREEN=1; export STARTED_SCREEN mkdir -p -- "$HOME/lib/screen-logs" screen -RR -S main || echo "Screen failed! continuing with normal bash startup" esac fi That is attach (or create) the screen session called "main" ...



Only top voted, non community-wiki answers of a minimum length are eligible