Hi,so today is my first day with linux.
I have some scripts from a friend and now im trying to run them but it doesnt work. So what i tried is:
-Moved the scripts to a specific directoy (into my document folder)
-then i opened the standard terminal in ubuntu (GNOME-Terminal)
-i typed in "Ls", then "cd Dokumente" and saw my scripts
-next i typed in "chmod +x Scriptname.sh" -->nothing happened
-then i typed "-/Scriptname.sh -->nothing happened
What i am doing wrong? Is the Script uncorrect?
Here it is:
#!/bin/sh
a=1
k=$(expr $# - 2)
for i in $@
do
if [ $k -lt $a ]
then
echo "$i"
fi
a=$(expr $a + 1)
done
I dont know if the script should return something but i see a "echo" so i think it should.
Should i use another Terminal? Or another editor? Im using notepad++ on windows and gedit on linux
Ups, my fault, i typed ./ Sry for that. Same goes with "sh Scriptname.sh", nothing happens.
I tried ls -1, it just list my scripts, but still not working.
SO the script i posted should return the last 2 parameter. MAybe i need to set them somewhere?
THX
---------- Post updated at 02:57 PM ---------- Previous update was at 02:35 PM ----------
yep, that was the error. i need to set the parameter-> sh Scriptname.sh 1 2 3
and make let us make both of them executable with:
chmod +x test.sh test2.sh
Then see what happens when you execute the commands:
./test.sh "a b c" "x $HOME z" 'd $HOME f'
./test2.sh "a b c" "x $HOME z" 'd $HOME f'
Do you understand why your test.sh command produces eight lines of output while the above test2.sh command with the same arguments only produces two lines of output? Which one of them do you think does a better job of displaying its last two parameters?