I have a folder full of *.command files on my OS X workstation.
(For those that don't know, *.command files are just shell scripts that launch and run in a dedicated Terminal window).
I've dragged this folder onto my Dock to use a "stack" so I can access and launch these scripts conveniently via a couple clicks.
I want to add a new "run-all.command" script to the stack that runs all the *.command files in the same stack with the obvious exception of itself.
My Bash chops are too rusty to recall how you get a list of the *.command files, iterate them, skip the file that's running, and execute each (in this case I'd be using the "open" command so each *.command opens in its own dedicated Terminal window).
Can somebody please help me out?
The first is -maxdepth 1 which prohibits reiteration to other folders. The second is -mindepth 1 which prevents the source folder from being included in the results to be transferred. The third option is the -not -name unwanted_filename option that uses the unwanted filename as an index to list the remaining content.
A quick way would be to modify the tux filename so that your move command will not match. don't use ".", as that will only move files that have a "." in the name. Just "*" is enough.
$@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
We can run all scripts in a directory or path using "run-parts" command. The run-parts command is used to run scripts or programs in a directory or path. One disadvantage with run-parts command is it won't execute all scripts. It will work only if your scripts have the correct names.
How about something like this:
#! /bin/bash
for x in ./*
do
if [ "$x" != "$0" ]
then
open $x
fi
done
where $0 automatically holds the name of the script that's running
Using @bbg's original script as a starting point and incorporating the comments from @Jefromi and @Dennis Williamson, and working out some more directory prefix issues, I arrived at this working version:
#!/bin/bash
for x in "$(dirname $0)"/*.command
do
if [ "$(basename $x)" != "$(basename $0)" ]
then
open "$x"
fi
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With