LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-02-2011, 02:13 AM   #1
choconlangthang
LQ Newbie
 
Registered: Dec 2010
Posts: 8

Rep: Reputation: 0
help with simple shell scripting


Hi,
I'm a Linux newbie, pls help me with this. I want a simple for loop to open N terminal windows (supposed to be input at runtime), I coded this way

Code:
#!/bin/bash
LIMIT = 10 #hard-coded since I dont know how to take input on the fly

for ((a = 1 ; a<= LIMIT; a++))
do
  gnome-terminal -e "ssh -X user@blablaserver.com" 
done

exit 0
It always got error "command not found", could anyone help pls? tks
 
Old 05-02-2011, 02:19 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
The complete error message should reveal the solution:
Code:
line 2: LIMIT: command not found
the word not recognized as a command is LIMIT. Indeed when you assign a variable, you should pay attention to the extra blank spaces: actually they must not be there, that is the equal sign should be immediately after the variable name without spaces before and after:
Code:
LIMIT=10
Regarding the input from the user, try the read statement, e.g:
Code:
read -p "How many terminal sessions? " ans
for ((a = 1 ; a <= ans; a++))
do
  gnome-terminal -e "ssh -X user@blablaserver.com" 
done
Hope this helps.
 
Old 05-02-2011, 02:30 AM   #3
choconlangthang
LQ Newbie
 
Registered: Dec 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
The complete error message should reveal the solution:
Code:
line 2: LIMIT: command not found
the word not recognized as a command is LIMIT. Indeed when you assign a variable, you should pay attention to the extra blank spaces: actually they must not be there, that is the equal sign should be immediately after the variable name without spaces before and after:
Code:
LIMIT=10
Regarding the input from the user, try the read statement, e.g:
Code:
read -p "How many terminal sessions? " ans
for ((a = 1 ; a <= ans; a++))
do
  gnome-terminal -e "ssh -X user@blablaserver.com" 
done
Hope this helps.
Sublime answer, works like a champ, tks.

For the knowledge, space doesn't affect anything in the for loop, I can put either
Code:
for ((a = 1 ; a <= ans; a++))

or
for ((a=1 ; a<= ans; a++))
and it still works (?)

And I bet the best thing to ask is you have a link to a practical shell scripting for user (not admin)?
 
Old 05-02-2011, 02:42 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Yes. It is a specific syntax of the for loop, that resembles the C loops and since in C there is not such a limitation (with or without spaces is the same) you are free to put them or not inside the double parentheses construct.

To learn shell scripting you can check:
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html (PDF available)
http://www.tldp.org/LDP/abs/html/index.html (PDF available)
For the command line in general:
http://www.linuxcommand.org/tlcl.php
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
in shell scripting how to compare strings from two different simple .txt files tej16 Linux - Newbie 1 07-29-2010 02:34 AM
Shell scripting question (simple) Leon W. Malinofsky *BSD 8 07-31-2008 09:48 AM
simple question regarding shell scripting branche_dude Linux - Newbie 8 07-21-2006 02:35 AM
simple shell scripting problem noir911 Programming 11 03-14-2006 01:27 AM
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 03:41 AM


All times are GMT -5. The time now is 05:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration