Search This Blog

Saturday, June 30, 2007

A simple bash script to change a file name

The following script will replace "mydata.dat" by "my22data.dat".


#!/bin/bash
mv mydata.dat my$1data.dat

If the script name is "changefile", type and enter in a shell prompt:

changefile 22

22 is the argument ($) taken as $1, and 1 means the first argument. In this case, there is only one argument.

No comments:

Labels