From 7fca3e9ab68c00050bba46e153672f522db411a3 Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Thu, 26 Dec 2013 20:12:11 +0100 Subject: [PATCH] Created test-script for args and fixed typo i lab7e2 (thx to Fredrik who pointed it out) --- Labb7/ovning2.sh | 2 +- Labb7/ovning2_zenity.sh | 2 +- Misc/test_args.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 Misc/test_args.sh diff --git a/Labb7/ovning2.sh b/Labb7/ovning2.sh index 1a1467f..5339670 100755 --- a/Labb7/ovning2.sh +++ b/Labb7/ovning2.sh @@ -18,7 +18,7 @@ if [ ! -w `dirname $File` ]; then exit 1 fi -for bin in $Awk $Dialog $Printf; do +for Bin in $Awk $Dialog $Printf; do if [ ! -x $Bin ]; then echo "Can't execute $Bin" exit 1 diff --git a/Labb7/ovning2_zenity.sh b/Labb7/ovning2_zenity.sh index 81c369f..a8ea39b 100755 --- a/Labb7/ovning2_zenity.sh +++ b/Labb7/ovning2_zenity.sh @@ -24,7 +24,7 @@ if [ ! -w /tmp/ ]; then exit 1 fi -for bin in $Awk $Zenity $Printf $Rm; do +for Bin in $Awk $Zenity $Printf $Rm; do if [ ! -x $Bin ]; then echo "Can't execute $Bin" exit 1 diff --git a/Misc/test_args.sh b/Misc/test_args.sh new file mode 100755 index 0000000..32f8967 --- /dev/null +++ b/Misc/test_args.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Jack-Benny Persson +# LX13 +# Just testing out $@ and $* + +Count=1 +for param in "$*"; do + echo "\$* Parameter #$Count = $param" + ((Count++)) +done + +Count=1 +for param in "$@"; do + echo "\$@ Parameter #$Count = $param" + ((Count++)) +done + +echo "" +echo "Testing with an array" +echo "---------------------" + +Count=1 +Test=($@) + +Count=0 +while [ $Count -lt ${#Test[@]} ]; do + echo "Index #$Count is ${Test[$Count]}" + ((Count++)) +done + + +