Archive for January, 2008

filenames …

The whole article …..

Here's where a few examples would have helped.
To understand the man page I simply experimented 
with the echo command and several shell variables. 
This is what it all means:
      Given:
            foo=/tmp/my.dir/filename.tar.gz 

      We can use these expressions:

      path = ${foo%/*}
          To get: /tmp/my.dir (like dirname)
      file = ${foo##*/}
          To get: filename.tar.gz (like basename)
      base = ${file%%.*}
          To get: filename 
      ext = ${file#*.}
          To get: tar.gz 

      Note that the last two depend on the assignment made in the second one

Here we notice two different "operators" being used inside the parameters (curly braces). 
Those are the # and the % operators. 
We also see them used as single characters and in pairs. 
This gives us four combinations for trimming patterns off the beginning or end of a string:

${variable%pattern}
    Trim the shortest match from the end 
${variable##pattern}
    Trim the longest match from the beginning 
${variable%%pattern}
    Trim the longest match from the end 
${variable#pattern}
    Trim the shortest match from the beginning 

basic arithmetics

So I think it is very simple to do some shell scripting, but when you have to calculate some simple variables it is not very handy. So I asked my friend Google and here are some of the result, simply to add, subtract, multiply vars in the bash language!

VAR=55             # Assign integer 55 to variable VAR.
((VAR = VAR + 1))  # Add one to variable VAR.  Note the absence of the '$' character.
((++VAR))          # Another way to add one to VAR.  Performs C-style pre-increment.
((VAR++))          # Another way to add one to VAR.  Performs C-style post-increment.
echo $[VAR * 22]   # Multiply VAR by 22 and substitute the result into the command.
echo $((VAR * 22)) # Another way to do the above.
 
 
# some date arithmetics (yestarday and one month ago)
date -d “-1 day” +%d%m     #will give me the yesterdays date.
date -d “-1 month” +%d%m  #will give me date one month previous.
 
Example: 
YESTERDAY=`date -d"-1 day" "+%Y.%m.%d"`;
echo $YESTERDAY;

install websvn

$ svn co http://wedsvn.tigris.org/svn/websvn/trunk www/websvn --username guest
 
$ cd www/websvn
$ cp include/distconfig.inc include/config.inc
$ vim include/config.inc
 
// Uncomment and edit this line:
$config->addRepository("My Projects", "file:///home/<username>/svn");