/home/drscream

  • home
  • blog
  • gallery
  • studies
  • about
  • bash, sequences of numbers or characters

    In bash there is an easy way to generate a sequence of numbers or characters. By defining a start and stop character with the ‘..’ in between:

    $ echo {a..z}
    a b c d e f g h i j k l m n o p q r s t u v w x y z

    The example above works with lower and upper case characters. Use upper and lower case characters in mix:

    $ echo {A..z}
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [  ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z

    It also work with numbers:

    $ echo {0..9}
    0 1 2 3 4 5 6 7 8 9
    $ echo {0..22}
    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

    Another way to generate a list of numbers is using the command line tool seq:

    $ seq 1 4
    1
    2
    3
    4

    To change the delimiter you can use the parameter -s “delimiter”, for example with a space:

    $ seq -s " " 1 10
    1 2 3 4 5 6 7 8 9 10

    Posted

    September 4, 2009

    Tags

    bash, characters, delimiter, numbers, seq, sequence

    1 comment

  • DOS bash prompt

    Yes it’s mindless :-)

    PS1='C:${PWD//\//\\\}>'

    Posted

    June 9, 2009

    Tags

    bash, dos, mindless

  • BashBox

    The code:

    #/bin/bash
    
    bashBox () {
    	str="$@"
    	len=$((${#str}+4))
    	for i in $(seq $len); do echo -n "*"; done;
    	echo; echo "* "$str" *";
    	for i in $(seq $len); do echo -n "*"; done;
    	echo
    }
    
    bashBox "Yea, a bash Box"

    The output:

     % ./bashbox.sh
    *******************
    * Yea, a bash Box *
    *******************

    Posted

    May 19, 2009

    Tags

    bash, box, code

  • bash variable set default value

    Yeaaa :-) Yesterday i’ve found a nice way to set an default value for bash variables.
    I use this way if parameter 1 isn’t assigned by the user. Here a small example:

    ip=${1-'10.1.1.1'}

    If $1 isn’t assigned by the user the default 10.1.1.1 is set as value of $ip.

    Posted

    March 29, 2008

    Tags

    bash, linux

  • Find easy empty directorys with ‘find’

    With find you can everything but you must know it :)

    find . -type d -empty

    [drscream@havanna] ~/Pictures/upload
     % find . -type d -empty
    ./Artwork/html/thumb
    ./Artwork/Photography/html/thumb
    ./html/thumb
    

    Posted

    March 2, 2008

    Tags

    bash, linux

  • How to find out your Tcl version

    It’s so easy, i’ve only searched a day long for that easy result:-P

    [drscream@havanna] ~
     % tclsh
    % puts $tcl_version
    8.4
    

    Posted

    March 1, 2008

    Tags

    bash, linux, macosx, tcl

  • Router, check the internet connection

    Currently i’ve some problems with my router. The reconnect only work sometimes… . So i’ve started to write a small bash script, to check that connection. The script run every hour and start a reconnection if no pppoe connection is available.

    
    #!/bin/bash
    #--------------------------------------------------------------------
    # $Id: checkIConnect,v 0.1 2008/02/11 17:17:26 drscream Exp $
    # Copyright 2008 Frubar Network (drscream@frubar.net)
    #--------------------------------------------------------------------
    
    ##
    ## main
    ##
    errors=0
    ns_ip=$(cat /etc/resolv.conf | sed 's/nameserver //g' | head -n 1)
    
    ## device check
    $(/sbin/ip a s dev ppp0 > /dev/null 2>&1)
    if [ $? -gt 0 ]; then
            echo "ERROR: Device not found!"
            let errors=$errors+1
    fi
    
    ## nameserver, ping check
    $(ping -c 4 $ns_ip > /dev/null 2>&1)
    if [ $? -gt 0 ]; then
            echo "ERROR: Ping doesn't work!"
            let errors=$errors+1
    fi
    
    echo "Code: $errors"
    
    if [ $errors -gt 0 ]; then
            echo "INFO: reconnect internet"
            /opt/fruky/bin/pppoe-restart
    fi
    

    Posted

    February 11, 2008

    Tags

    bash, linux

  • Bash, get the last day of the month

    Easy way to get the last day is to look if the next day is the first of the month. Now here are a small bash script thats show you the functionality:

    if [ $(date -d tomorrow +%d) -eq 1 ]; then
        echo "OK: last day of the month"
    else
        echo "NOK: not the last day of the month"
    fi
    

    Posted

    January 27, 2008

    Tags

    bash, linux

  • Argument list too long

    Wer kennt es nicht, gerade wenn man viele Datein loeschen moechte:

    Argument list too long.

    Ein einfacher “workaround” ist das verwenden von xargs:

    ls | xargs rm

    ( Vielen Dank an adminlife.net )

    Posted

    January 25, 2008

    Tags

    bash, linux

  • vim dynamic fileheader

    I’ve currently programming some small bash scripts and I would use my default Frubar fileheader for every script:

    "--------------------------------------------------------------------
    " $Id: vimrc.header,v 0.1 2008/01/23 16:05:22 drscream Exp $
    " Copyright 2008 Frubar Network (drscream@frubar.net)
    "--------------------------------------------------------------------
    

    At this point i’ve written a small vimrc file, thats allows me to insert the header by typing ,fh. The vimrc.header file can be found here!

    To use this script insert the following in your ~/.vimrc file:

    " Source vimrc.header file, code header function
    let VIM_HEADER=expand("~/.vim/vimrc.header")
    if filereadable(VIM_HEADER)
            exe "source " VIM_HEADER
    endif
    

    Posted

    January 23, 2008

    Tags

    bash, linux, vim

« Previous Entries