nbalonso.com

Two Useful Bash Commands

| Comments

I have noticed that the blog does not have a tag for #bash , even though I spend much of my time with it at the office. So I’ve decided to post two useful commands that made my life easier at the time

The first one is the tr command used to return whatever result all in lowercase or uppercase as needed. It works perfectly fine in a pipe so you could do something like this to get the uppercase transformed to lowercase:

1
2
bash-3.2$ echo "Nbalonso.COM" | tr "[:upper:]" "[:lower:]"
nbalonso.com

The second command is jot and allows you to create random number of a given range. The syntax for this is

jot -r [for calling a random number] [number of results you need] [minimum valid value] [maximum valid value]

An example would be

1
2
3
4
bash-3.2$ jot -r 3 1 100
75
35
94

You could use this to, for example, distribute the clients connecting to one or another server by doing the following and pointing some clients to http://susupdateserver01.com and some others to http://susupdateserver02.com

1
bash-3.2$ $DEFAULTS write $SUSPLIST CatalogURL "http://susupdateserver0`jot -r 1 1 2`.com:8088/index.sucatalog"

I hope these are useful for your scripts. For sure you can find many uses for these two commands in your bash scripts

Comments