Just another [stupid] BASH one-liner


Just another stupid yet handy one-liner I came up with while doing nothing useful.

I was sitting in front of a shell, wondering why some files in some directory existed with three different extensions while others didn’t, when it hit me that all files should exist with three different extensions for something altogether different to work. Instead of manually touch‘ing all those files that didn’t exist with all three different extensions, I farted the following BASH one-liner.

for i in *.frm; do base=$(echo $i | sed s/.frm$//); if [ ! -f $base.MYD ] && [ ! -f $base.MYI ]; then touch $base.MY{D,I}; fi; done

;-) The fact that my initial speculation that doing so would get something altogether different to work failed miserably is irrelevant.

4 thoughts on “Just another [stupid] BASH one-liner

  1. yours is not a one-liner (unnecessarily too long), should have done it this way:

    for i in *.frm; do touch ${i%.frm}.{MYD,MYI}; done

  2. The fact that something altogether different failed to run, may be needed you to copy rather than just touch:

    for i in *.frm; do cp $i ${i%.frm}.MYD && cp $i ${i%.frm}.MYI; done

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s