Tag Archives: bash

How to update bash on Ubuntu 10.10 Maverick – fix shellshock

Ubuntu 10.10 Maverick is now past the end-of-life / end-of-support phase so it will no longer be getting any updates, including security updates. To update / patch bash you must do so from source. Here are the commands to download the source for bash and build and install it. Update – the instructions below were previous instructions, but to prevent the continuous need to apply patches there is an updated method using git: New Method 1 This method downloads a tarball of the latest source code and is around 7MB in size. wget “http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz” unzip bash-master.tar.gz cd bash-master ./configure make make install New Method 2 This method uses git and requires ~ 150MB of space ( includes version history ) but makes future updates easier with a git pull: git clone git://git.sv.gnu.org/bash.git cd bash ./configure make make install Old Method mkdir src cd src wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz #download all patches for i in $(seq -f “%03g” 0 27); do wget http://ftp.gnu.org/gnu/bash/bash-4.3-patches/bash43-$i; done tar zxvf bash-4.3.tar.gz cd bash-4.3 #apply all patches for i in $(seq -f “%03g” 0 27);do patch -p0 < ../bash43-$i; done #build and install ./configure && make && make install cd .. cd .. rm -r src Testing Bash for Shellshock Paste this into a terminal env x='() { :;}; echo vulnerable’ bash -c “echo this is a test” Desired Result bash: warning: x: ignoring function definition attempt bash: error importing function definition for `x’ this is a test If you get something like the above message you’re good … Continue reading

Posted in Server Administration | Tagged , | 5 Comments

In what order are /etc/profile /etc/profile.d ~/bashrc and ~/.profile loaded ?

INVOCATION A login shell is one whose first character of argument zero is a -, or one started with the –login option. An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state. The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error. Tildes are expanded in file names as described below under Tilde Expansion in the EXPANSION section. When bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands 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. When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists. When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the –norc option. The –rcfile file option … Continue reading

Posted in Server Admin | Tagged , | Leave a comment

bash: send last command to quicksilver

In your /Users/user/.profile add the following: export HISTCONTROL=erasedups:ignorespace alias cpc=” history | cut -c 8- | tail -n 2 | head -n 1 | qs” The first line prevents duplicate commands in the bash history, and also keeps any commands starting with a space from showing up in history. The second line sets an alias of “cpc” which will get the second to last command (cpc being the “last” command), and sends it to quicksilver. Now, launch a new terminal window and type a command, like “ll -l”, and then type “cpc” and quicksilver should pop up with “ll -l” in the first pane. I find this most useful when I’ve just executed a long or complicated command and want to easily grab it, either to save it or modify it.

Posted in Mac | Tagged , , , , | 1 Comment

Replacing Variables with Bash

$(var:pos[:len]) # extract substr from pos (0-based) for len $(var/substr/repl) # replace first match $(var//substr/repl) # replace all matches $(var/#substr/repl) # replace if matches at beginning (non-greedy) $(var/##substr/repl) # replace if matches at beginning (greedy) $(var/%substr/repl) # replace if matches at end (non-greedy) $(var/%%substr/repl) # replace if matches at end (greedy) ${#var} # returns length of $var ${!var} # indirect expansion

Posted in Web Development | Tagged , | Leave a comment