Skip to content

Instantly share code, notes, and snippets.

@shtrih
Created August 1, 2018 16:44
Show Gist options
  • Save shtrih/038a753fa6ec3394d036eeddd6457f15 to your computer and use it in GitHub Desktop.
Save shtrih/038a753fa6ec3394d036eeddd6457f15 to your computer and use it in GitHub Desktop.
Bash loop command over arguments
#!/bin/sh
# usage: ./loop.sh "command name" arg1 arg2 2>&1 | tee loop.log
for i; do
if [ "$1" = "$i" ]; then
continue;
fi
echo "\n\n" $1 "$i";
VAR=$($1 "$i");
echo "$VAR";
done
# run command «php artisan index:links -vvv» with arguments
user@user$> ./loop.sh "php artisan index:links -vvv" 103045617 90087612 2>&1 | tee loop.log
# loop.log content:
php artisan index:links -vvv 103045617
Indexing document "103045617"
Found 43 links
Successfully indexed document "103045617"
php artisan index:links -vvv 90087612
Indexing document "90087612"
[01-Aug-2018 16:41:16 UTC] [2018-08-01 16:41:16] local.WARNING: Rule not found "20180521"
Found 11 links
Successfully indexed document "90087612"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment