Sponsored Content
Top Forums Shell Programming and Scripting Dazed and confused...need help Post 303028827 by alteruniverse on Tuesday 15th of January 2019 05:03:54 PM
Old 01-15-2019
Dazed and confused...need help

I have one script - two versions; these are test scripts to solve my problem/issue.
The difference between the two scripts is that the "for....loop" in script 'loop1' uses a variable ($xlim) to control the loop; whereas in script 'loop2' the loop parameter are fixed integers.

'loop1'
-------------------------------------------------------
Code:
#!/bin/bash

zz=3
yy=0
xlim=5

for i in {1..$xlim}; do 
   echo "I = $i"
   ((yy=$zz\*i))
   echo "Welcome $i times  $yy"
done

-------------------------------------------------------------
OUTPUT:
===================================
Code:
$ loop1
I = {1..5}
./loop1: line 9: ((: {1..5}: syntax error: operand expected (error token is "{1..5}")
Welcome {1..5} times  0

===================================

'loop2'
------------------------------------------------------------
Code:
#!/bin/bash

zz=3
yy=0
xlim=5

for i in {1..5}; do 
   echo "I = $i"
   ((yy=$zz\*i))
   echo "Welcome $i times  $yy"
done

---------------------------------------------------------------------

OUTPUT
=====================================
Code:
$ loop2
I = 1
Welcome 1 times  3
I = 2
Welcome 2 times  6
I = 3
Welcome 3 times  9
I = 4
Welcome 4 times  12
I = 5
Welcome 5 times  15

=====================

Of course, my actual script needs a 'parametric loop' like in script 'loop1'.
So why if one of the loop parameters is not a 'static' (constant) value does "I = {1..5}" and not "I = 1", i.e why does $i substitute to "{1..5}"?

I have not been able to find any help otherwise and would appreciate any advice!

Last edited by vgersh99; 01-15-2019 at 06:14 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

confused,,,,

Hi,,, is there any possibility to install Linux in my P.C which is use Win98 without loose anything from my hard disk???? ---------------------------------------------------------------------------------- Is it better for a newbie in this kind of OS to install Linux instead of... (5 Replies)
Discussion started by: spyros
5 Replies

2. UNIX for Dummies Questions & Answers

confused

hi! how when i'm chattin inside com there was this chatter andi don't know what he did but he saw all my files inside my shell. what did he do? (4 Replies)
Discussion started by: hapiworm
4 Replies

3. Shell Programming and Scripting

confused with cp

may i know what cp $1 $2 $0 $2 does? (12 Replies)
Discussion started by: C|[anti-trust]
12 Replies

4. UNIX for Dummies Questions & Answers

confused

A red hat linux ftp server exists in which a file exists. My problem is I need to connect to this server from my windows xp terminal which is in the same network & retrieve the file then convert it to xcel for some data Pls advs commands and procedure to connect to the machine...oh my god... (1 Reply)
Discussion started by: sauravjung
1 Replies

5. Shell Programming and Scripting

sed very confused

Hello experts, I have this complicated code that output value in between pattern and add "a string" to the front of the output. The problems I have many pattern that are the same. so I want to know how to get the value between 1st pattern, 2nd pattern etc. Any suggestions? sed -n... (14 Replies)
Discussion started by: minifish
14 Replies

6. UNIX for Dummies Questions & Answers

Confused with the permission

Hi, One of the directory in my folder has the following persion : drwxr-sr-x Can any one explain this permission and how can his occur ? This folder is created with Win SCP. Any folder created with win SCP is being set to this permission only. (1 Reply)
Discussion started by: risshanth
1 Replies

7. Solaris

Confused c#t#d#s#

I am confused c#t#d#s# once I learn the following : slice 0 ...... 0 to 2520 slice 1....... 2521 to 2840 slice 6........2841 to 8891 slice 2........0 to 8891 really really confused. Please explain. (8 Replies)
Discussion started by: deltakutty
8 Replies

8. Ubuntu

New and Confused

Hello, I am having a problem with Dual Booting Windows XP Pro and Linux Mint. I have Three Hard Drives, One Hard Drive has Linux Mint Loaded on it. When it is hooked up to the computer by itself it works great. This is an IDE Drive. The Second Hard Drive has Window XP Pro loaded on it.... (3 Replies)
Discussion started by: Forextrading
3 Replies

9. Shell Programming and Scripting

Confused with if/then

Hi All, I'm pretty new to this so please bear with me... I'm trying to write a bash script to first search in a file for a string of characters; if the characters exist than skip the rest of the code until you get to the last line and run that command /sbdin/ldconfig; if the string doesn't... (2 Replies)
Discussion started by: gmdune
2 Replies
service(8)						      System Manager's Manual							service(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start command. service --status-all runs all init scripts, in alphabetical order, with the status command. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. ENVIRONMENT
LANG, TERM The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton, update-rc.d(8), init(8), invoke-rc.d(8). Jan 2006 service(8)
All times are GMT -4. The time now is 03:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy