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

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to start a Shell Script in a VirtualBox(Ubuntu)?
# 1  
Old 07-13-2016
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:
Code:
#!/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.
# 2  
Old 07-13-2016
Quote:
Originally Posted by easy123
.
.
.
-i typed in "Ls", then "cd Dokumente" and saw my scripts
I guess you typed ls when you saw your scripts. You shouldn't have seen anything after cd ... (except, maybe, a different system prompt).

Quote:
-next i typed in "chmod +x Scriptname.sh" -->nothing happened
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.

Quote:
-then i typed "-/Scriptname.sh -->nothing happened
No error message? Hmmm. Try ./Scriptname.sh.

Quote:
Im using notepad++ on windows
... and leave it there!
Quote:
and gedit on linux
fine!
# 3  
Old 07-13-2016
Quote:
No error message? Hmmm. Try ./Scriptname.sh .
Ups, my fault, i typed ./ Smilie 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 ----------

Quote:
Originally Posted by easy123

SO the script i posted should return the last 2 parameter. MAybe i need to set them somewhere?
yep, that was the error. i need to set the parameter-> sh Scriptname.sh 1 2 3

Thx
# 4  
Old 07-13-2016
Compare the results you are getting with your current version of test.sh with this alternative (let's call it test2.sh):
Code:
#!/bin/sh
[ $# -gt 2 ] && shift $(($# - 2))
printf '%s\n' "$@"

and make let us make both of them executable with:
Code:
chmod +x test.sh test2.sh

Then see what happens when you execute the commands:
Code:
./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?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to stop and start server

Hi, I need to create a shell script for automated server patching, with the following scenario: I have two Linux servers Primary and secondary. Server patching should start on Primary 1st and then secondary. 1st check both servers are up and running. Then stop primary and patching will... (1 Reply)
Discussion started by: rcroyal88
1 Replies

2. Ubuntu

Start Ubuntu without init

Is it possible to start Ubuntu (or any other modern UNIX OS) or get it to any usable state without the init software. By this I mean replacing init with bash and manually initializing all the components. So far i've managed to edit grub at start and get the bash shell but I don't know where... (3 Replies)
Discussion started by: Kadikis
3 Replies

3. Linux

Ubuntu 12.04.2 server amd64 on Virtualbox

Hello, I could not find the appropriate forum for my problem to boot Ubuntu 12.04.2 server amd64 on Oracle Virtualbox(4.3.0 BETA1) within Win 7, so I posted here to start. For some reason Ubuntu could not boot anymore, and I am looking any suggestion before I re-install it as I do not want to... (0 Replies)
Discussion started by: yifangt
0 Replies

4. UNIX for Advanced & Expert Users

start virtual machine in Virtualbox giving username and password.

i have found a way to start vm with commanda as follows - VBoxManage startvm <uuid>|<name> it is installed inside oracle virtualbox. in vmware we have a way to do this -- $vmware-cmd -v -H localhost -U user -P password /var/lib/vmware-server/Virtual\ Machines/Ubuntu/Ubuntu.vmx... (0 Replies)
Discussion started by: upvan111
0 Replies

5. Shell Programming and Scripting

Shell Scripting.... How to start a same script in 3 different logins?

Hi, I’ve a shell script. If I trigger the script it takes one day to complete the execution. I’ve to start the same script in 3 different logins of Unix machine simultaneously. Do you have any idea how can I make it? Please suggest. Thank you.. Stop making the font size smaller than... (3 Replies)
Discussion started by: testin
3 Replies

6. UNIX for Dummies Questions & Answers

unable to start shell script

Hi, Pleasse could someone advise why i'm getting this error below - No such file or directory dev6:$ ls -ltr ReleaseManagement.sh -rwxr-xr-x 1 dev fix 4830 Aug 22 11:13 ReleaseManagement.sh dev6:$ ./ReleaseManagement.sh : No such file or directory dev6:$ thank you (2 Replies)
Discussion started by: venhart
2 Replies

7. Shell Programming and Scripting

Help with stop/start Shell Script.

Hi All, I would like to develop a shell script for stop & start an application server (1-4) on Solaris box. Here are the user requirements for this task. 1. User will input the option which server they wish to stop. 2. Will clear cache files from specific location. 3. ... (1 Reply)
Discussion started by: venga
1 Replies

8. Virtualization and Cloud Computing

Creating VirtualBox-Image as "harddisk" by shell-script

Hello, I'm trying to create a VirtualBox "harddisk" and put an dd-image into it. This image shoudn't work as a virtual maschine, I just want to be able to mount it to an folder. How can I do this with an shell script? Sebi ---------- Post updated at 10:36 AM ---------- Previous update... (0 Replies)
Discussion started by: Sebi0815
0 Replies

9. Shell Programming and Scripting

Ubuntu shell script

I got the below script on line but can't seem to get it to work as there are syntax errors where 'len' is shown. Can anyone help with this?? echo " Enter the String" read str echo $str > str.txt len = 'echo $str | wc -c' len = 'expr $len -1' c= 0 , w = 0 , s = 0 , i = 1 echo " Length... (1 Reply)
Discussion started by: lucianvibz
1 Replies
Login or Register to Ask a Question