Sunday, November 29, 2009

One script with different script names.

Sometimes I want to have my bash script behave differently based on how I call it without having to set up different parameter inputs. For example, I might have a script that can sync a file from a local server to one of two remote servers. I can make my script to take in parameters so I can call it using 'syncfiles -h serverA; syncfiles -h serverB', but sometimes I forget what my params are and it's easier to remember 'syncToA' or 'syncToB'.

To do this is pretty simple, yet I always have to look it up each time so I'm writing this as note to myself.


echo $0

if echo $0 | grep "syncToA" > /dev/null
# do stuff
elif echo$0 | grep "syncToB" > /dev/null
# do stuff

Next, create symlinks to the original source files with the names you chose (i.e. 'symlink syncToA syncfiles').

No comments:

Post a Comment