Sponsored Content
Top Forums Shell Programming and Scripting Learning curve to understand bash iteration Post 302611219 by Corona688 on Thursday 22nd of March 2012 11:42:01 AM
Old 03-22-2012
My code ought to do what you want, then.

With a little testing I find you can do nearly the same idea in csh, too. Put the expression you want in a variable, and keep changing it.

Code:
#!/bin/sh
# Bourne shell version

I=0

while [ "$I" -le 2 ]
do
        RANGE="[0-$I]"

        echo
        echo "Files in range $RANGE"
        echo *${RANGE}* # Will expand to *[0-1]*, etc

        I=`expr $I + 1`
done

Code:
#!/bin/csh
# csh version

@ I = 1
while ($I <= 2)
        set VAR="[0-$I]"

        echo
        echo "Files in range $RANGE"
        echo *${RANGE}*

        @ i++
end

Incidentally -- neither of these program uses arrays, in either language.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

learning curve's too steep

I tried PC-BSD a year or 2 ago, but the command-stuff wasn't clear to me, not knowing anything about UNIX. I decided to go from scratch to learn more and installed FreeBSD7. Now I find this is taking too much time (which I don't have; full time job + playing music + being over 50) to learn... (5 Replies)
Discussion started by: catch22
5 Replies

2. Shell Programming and Scripting

bash shell: 'exec', 'eval', 'source' - looking for help to understand

Hi, experts. Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) : exec eval source I've tryed to read the manual pages but did not get much. Also could not get something useful from Google search - just so much and so not exactly, that is... (3 Replies)
Discussion started by: alex_5161
3 Replies

3. Shell Programming and Scripting

Understand Bash scripting encryption

Dear all, I have been working with Linux for quite few years but never required to learn Bash and Linux really dep doan. I want to learn bash I bought books and Have been reading on the Internet but I cannot find my answers, maybe I am blind. For example: What does this means? # for i in... (4 Replies)
Discussion started by: renpippa
4 Replies

4. Shell Programming and Scripting

I want to understand bash better

Hi everyone, I have some questions regarding bash and my initializer files: when I look at my bashrc file, I see lots of "export".. export MAGICK_HOME="$HOME/bin..etc".. what does export really mean? in my bashrc, I have a line: "umask 0002" ... what does that do? I have a bash_profile... (6 Replies)
Discussion started by: patrick99e99
6 Replies

5. Shell Programming and Scripting

Do not understand why my while loop fail (bash)

Hi again :) I still need your help now... #!/bin/bash SIZE=`ls -s text.txt` while do done My problem is that the line "while ..." still print the same value after the first loop. In one instruction change the size of text.txt I've run my bash script in debug mode, and the... (6 Replies)
Discussion started by: Link_
6 Replies

6. UNIX for Dummies Questions & Answers

Another Simple BASH command I don't understand. Help?

I have a text file called file1 which contains the text: "ls -l" When I enter this command: bash < file1 > file1 file1 gets erased. However if I enter this command: bash < file1 > newfile the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get... (3 Replies)
Discussion started by: phunkypants
3 Replies

7. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

8. OS X (Apple)

Plotting A Sine Curve Inside A Bash Shell...

Hi all... After mentioning the generation of a sinewave sweep generator in a previous thread in this forum this is the method I decided upon. It plots a sinewave inside an 80 x 24 terminal window. Although the original used bc (and the line is in the code but commented out) it is now... (4 Replies)
Discussion started by: wisecracker
4 Replies

9. Shell Programming and Scripting

I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works

Please help me understand how sort -k3,3 -k 4,4 short* works , is it sorting 3 and 4 th field ? what is the use of specifying 3,3 and 4,4 in sort and what is actually does and i see sort -k3 short* and sort -k3,3 -k 4,4 short* giving the same output. Sort output attached Please help (2 Replies)
Discussion started by: Antony Ankrose
2 Replies

10. Shell Programming and Scripting

How to understand special character for line reading in bash shell?

I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters... (3 Replies)
Discussion started by: duke0001
3 Replies
CHECKBASHISMS(1)					      General Commands Manual						  CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 07:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy