Shell Scripting: How to Automate Command Line Tasks Using Bash Scripting and Shell Programming by Cannon Jason

Shell Scripting: How to Automate Command Line Tasks Using Bash Scripting and Shell Programming by Cannon Jason

Author:Cannon, Jason [Cannon, Jason]
Language: eng
Format: epub, pdf
Published: 2015-09-13T16:00:00+00:00


cd /var/www

cp *.html /var/www-just-html

Let's say you want to do something for each file that matches a wildcard. In that case, you can use a for loop. Let's use a for loop to perform an action on all the html files in a directory.

The following script simply echoes to the screen the name of the file that is about to be copied, and then copies that file from the /var/www directory to the /var/www-just-html directory. Of course, you could do something more complex in this loop if you wanted.

Notice that the wildcard expression is being used where you would normally provide a list. This wildcard expression will expand to create a list of matching file and directories. In the case that the wildcard is not matched, the for loop is not executed. Also notice that we are explicitly changing into a directory before we use the wildcard.

#!/bin/bash



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.