Hardware Reference
In-Depth Information
Step 6: Run the Script
That's it! To run the script, type . /test.sh and press Return. The window should display
something like this:
Hello! The current date and time is:
Wed Jun 1 19:58:21 PDT 2014
And the current directory is:
/Users/jk
For fun, try switching to a different folder. For example, type
cd /Library/Preferences
and press Return to move to the /Library/Preferences folder. Now run the script again
by typing ~/test.sh and pressing Return. You'll see that it shows your new location.
Tip: Any time you need to put a new script on your system, follow these same steps
(although the script name and location may vary).
Try Another Script
Here's another script you may find useful. It changes the extension on all files in a folder
(for example, from .JPG to .jpeg )—something that's not easy to do in the Finder or on the
command line.
Repeat the preceding set of directions, with two differences. First, in Step 2, use a different
file name when you open nano:
nano br.sh
(That is, br for batch rename.) Then, in Step 3, type the following code instead:
#!/bin/bash
for f in $3/*.$1; do
base=`basename $f .$1`
mv "$f" "$3/$base.$2"
done
Search WWH ::




Custom Search