If you’ve got a string of items in bash which are delimited by a common character (comma, space, tab, etc) you can split that into an array quite easily. Simply (re)define the IFS variable to the delimiter character and assign the values to a new variable using the array=($<string_var>) syntax. The new variable will now [...]
Posts Tagged ‘terminal’
Convert a delimited string into an array in Bash
Posted: 9th March 2012 by Tim in BashTags: array, Bash, delimiter, IFS, linux, OIFS, script, scripting, string, terminal, unix
Ignoring the first line of output in a unix terminal
Posted: 31st January 2011 by Tim in Bash, Software Development, UbuntuTags: first line, ignore, linux, sed, sh, shell, terminal, Ubuntu, unix
Sometimes in a terminal you want to strip out the first line of output from a command. For example, you may want to generate a list of users which have tasks running using the ps command. This command puts a header at the top of the output. You can remove this header by piping the [...]
Checking the Ubuntu version number
Posted: 13th June 2010 by Tim in UbuntuTags: Bash, check, number, release, shell, term, terminal, Ubuntu, version
Ever jumped onto an Ubuntu server somewhere without knowing which operating system version it’s running? You can find this out with one simple command: lsb_release -a This will provide output like: Distributor ID: Ubuntu Description: Ubuntu 9.10 Release: 9.10 Codename: karmic
Checking for empty string in Bash
Posted: 19th May 2010 by Tim in BashTags: Bash, coding, dash, empty, language, linux, null, programming, script, scripting, SET, shell, string, terminal
In Bash you quite often need to check to see if a variable has been set or has a value other than an empty string. This can be done using the -n or -z string comparison operators. The -n operator checks whether the string is not null. Effectively, this will return true for every case [...]
List files which are not up to date in CVS
Posted: 5th October 2009 by Tim in Bash, CVS, UbuntuTags: Bash, cvs, grep, pipe, repository, script, shell, terminal
CVS is annoying in that if you want to find out which files have been modified or need updating, you can’t simply use the cvs status command as there’s too much information displayed. In order to make it useful, you really need to filter the output. Note: the following tutorial only works for linux computers [...]