How to start a Shell Script in a VirtualBox(Ubuntu)?

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

Hope you can help me.

I guess you typed ls when you saw your scripts. You shouldn't have seen anything after cd ... (except, maybe, a different system prompt).

Oh yes, for sure something happened (unless Scriptname.sh was executable before); you may not have seen it. run ls -l before and after that command.

No error message? Hmmm. Try ./Scriptname.sh .

... and leave it there!

fine!

Ups, my fault, i typed ./ :slight_smile: 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

Thx

Compare the results you are getting with your current version of test.sh with this alternative (let's call it test2.sh ):

#!/bin/sh
[ $# -gt 2 ] && shift $(($# - 2))
printf '%s\n' "$@"

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?