The Archives

  • 25.Feb.09
    Bash 4.0 released news | rafacas | (0)
    Via Slashdot I found out about bash version 4.0 being out. Bash is the GNU Project's Bourne Again SHell, a complete implementation of the POSIX.2 shell spec, but also with interactive command line editing, job control on architectures that support it, csh-like features such as history substitution and brace expansion, and a slew of other features. The new version fixes several bugs in the 3.x releases and introduces a bunch of new features. The most notable ones are associative arrays, improvements to the programmable completion functionality, case-modifying word expansions, co-processes, support for the `**' special glob pattern, and additions to the shell ...
  • 18.Feb.09
    Alias shell | fernape | (0)
    This command, when invoked without arguments, shows the list of aliases in your shell session: $>alias alias dir='ls -l' alias l='ls -alF' alias md='mkdir -p' It also allows you to create your own aliases: $>alias lc='ls --color' If for some reason, you want to delete an alias, you can use the unalias command: $>unalias lc Aliases can help you saving a lot of time by avoiding repetitive and long commands and options. If you want them to be permanent, you should add those definitions to your .bashrc file.
  • 14.Feb.09
    Is your site up? scripts | rafacas | (0)
    When I cannot reach one of my sites, I do not know if it is my problem, my ISP's or my hosting provider's. This is why I use the service down for everyone or just me. I have written a simple script which uses that service. Its usage is: $ ./ is up and the script is: #!/bin/bash # # 2009 - Rafa Casado - numargs=$# if [ $numargs -ne 1 ] then echo "Usage: $0 domain" echo "Ex: $0" exit 1 fi DOMAIN=$1 IS_UP=`wget -nv -O ...
  • 02.Feb.09
    Currency conversion script scripts | rafacas | (1)
    In this time of crisis perhaps we need to pay more attention to financial issues. I am interested in converting some currencies so I have written a script that given two currencies, converts on to the other. The script searches the info on Google Finance's page. An example of its usage is: $ ./ EUR USD 1 EUR = 1.316 USD The available currencies are: EUR - Euros USD - United State Dollar GBP - British Pound JPY - Japanese Yen CHF - Swiss Franc CAD - Canadian Dollar AUD - Australian Dollar INR - Indian ...
  • 16.Dec.08
    TTYtter: twitter client for real commandliners scripts, shell | rafacas | (2)
    If you are a twitter adict (I know you are already a commandliner ;) TTYtter is your client. TTYtter requires only Perl 5.005 or better, and either cURL or Lynx. It supports encryption as long as your Lynx or cURL does. If your client supports it you can configure TTYtter to use SSL changing the relevant URLs. These can be changed using TTYter options (-url, -rurl, -uurl, -wurl, -update, -dmurl and -frurl) or you can cut and paste the following code into your .ttytterrc file in your $HOME directory: url= rurl= uurl= wurl= update= dmurl= frurl= The default cURL's certificate bundle is old and may not support Twitter's current ...
  • 08.Dec.08
    Ctrl-X-E shell | fernape | (0)
    With this keystroke combination, you open the editor specified by the $EDITOR variable (or emacs if the variable is not set). Once you write the file and quit, bash will execute the commands written in the editor. This is especially useful when you want to write a small script.
  • 15.Nov.08
    Strings in bash shell | pfortuny | (0)
    Start with a string: $ a="hi, this is my beautifull string" Positional substrings: Substring from the 4th character on: $ echo ${a:3} this is my beautifull string Substring of length 4 from the 10th character: $ echo ${a:9:4} is m Substring modification: Substitute the first instance of a substring: $ echo ${a/full/ful} hi, this is my beautiful string Same example: $ echo ${a/h/H} Hi, this is my beautifull string Substitute all the instances of a substring: $ echo ${a//hi/HI} HI, tHIs is my beautifull string Substring removal: Remove the shortest match of a substring from the start: $ echo ${a#h*i} , this is my beautifull string Same, starting at the end $ echo ${a%i*g} hi, this is my beautifull str Remove the longest match of a ...
  • 17.Jul.08
    Roll the dice scripts | fernape | (5)
    Not a command, but a fun thing anyway. What if you need a dice (as I needed the other day while trying to play a game with my friends) and you don't have one? Bash can do it: $ while true;do let dice="$RANDOM % 6"; let dice=$dice+1;echo $dice;read;clear;done Though it's a long line, this is just an infinite loop in which we use the $RANDOM bash variable which generates a random number between 0 and 32767. After that, we divide it by 6 and take the remainder (so we have a number between 0 and 5) and add 1 to shift the interval ...
  • 15.Jun.08
    More on bash history shell | fernape | (2)
    Bash provides a powerful history system that helps you in repeating commands and arguments. For example, the !! command, repeats the last executed command. If you want to execute a command typed before the last one, you can select it with the following: !-number Something like this: $ ls $ ps $ !-2 The last command executes ls again. In addition, you can specify previous arguments too. This is done with the !:n command (n being a number). Let's see an example: $ less file.txt $ cp !:1 file_copy.txt The last command takes the first argument of the previous executed command and makes a copy with a different name. If this is not ...