HPUX KSH for loop issues.


 
Thread Tools Search this Thread
Operating Systems HP-UX HPUX KSH for loop issues.
# 1  
Old 09-23-2011
HPUX KSH for loop issues.

Wrote a KSH script on a RHEL server and moved it over to the HPUX server and it is not liking a loop that I put together. Here is the simple form of it that does not work in KSH:


Code:
for x in {0..$VARIABLE_NAME}
do
     echo $x
done

This works:


Code:
for x in {0..10}
do 

     echo $x 

done

I tried listing in the variable as "${VARIABLE_NAME}, but that did not work. I also tried "()" parenthesis and brackets "[]" but no luck. Any ideas? Again this works just fine on RedHat Linux. It does like the usage of a variable in the in span.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 09-24-2011 at 04:09 AM..
# 2  
Old 09-23-2011
It's just this ksh version can't do it. Use:
Code:
for x in `seq 0 $VARIABLE_NAME`
do
  echo $x
done

# 3  
Old 09-24-2011
By default on HPUX you won't find seq tool.

You can use while instead of for tho :
Code:
VAR=5
x=0
while [ $x -lt $VAR ]; do
x=$(( x + 1 ))
echo $x
done

Regards
Peasant.
# 4  
Old 09-26-2011
Quote:
I tried listing in the variable as "${VARIABLE_NAME}, but that did not work.
Listing in variable works but the syntax you used is bash not ksh (strict form)...The same in ksh your should not use:
Code:
A=`who am i -R`    
#Though it still works...
#but
A=$(who am i -R)

So:
Code:
for i in ${ls a*}; do echo $i; done
ksh: ${ls a*}: bad substitution
ant:/home/vbe/test $ for i in $(ls a*); do echo $i; done
a000
a001
a002
a003
a004
ant:/home/vbe/test $ uname
HP-UX
ant:/home/vbe/test $

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Issues with ksh

We are using ksh on Linux (Thats what architect told me). 1) When I am using up and down arrow key, I can not navigate to previous and next commands. How can I navigate commands in ksh ? Someone told me that I need to have bash shell installed ? Can I have bash shell installed on ksh ? OR can I... (3 Replies)
Discussion started by: paramshamnani
3 Replies

2. Shell Programming and Scripting

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 Replies

3. Shell Programming and Scripting

recent test -e ksh incompatibility in hpux?

On a very new (11.31) hpux machine, I can no longer execute shell fragements like: if ; then . .profile.foo fi and get "ksh: test: argument expected" if I convert this to -d or -f as appropriate (which I've not had to do on older versions of hpux (11.23) nor any other unix platform... (9 Replies)
Discussion started by: Peeter Joot
9 Replies

4. Shell Programming and Scripting

Need Script to Use CPUs on a HPUX server to simulate Workload Manager on HPUX.

I am running HPUX and using WLM (workload manager). I want to write a script to fork CPUs to basically take CPUs from other servers to show that the communication is working and CPU licensing is working. Basically, I want to build a script that will use up CPU on a server. Any ideas? (2 Replies)
Discussion started by: cpolikowsky
2 Replies

5. Shell Programming and Scripting

issues with a condition in a while loop

Hi, I am facing issues with test condition. I had a compound condition to write for both if and while, In one of the texts i referred, with a korn shell we can write compound statements like: ], however this doesn't worked for me. For example: if ] doesn't works, but if || worked. ... (1 Reply)
Discussion started by: amritps
1 Replies

6. UNIX for Advanced & Expert Users

KSH Login issues

Hi In my environment User have csh have default shell. In some cases some users requires KSH. We are using NIS as well as some local users. here my problem is recently in some of sun servers if users who have ksh as a default shell are trying to login with putty the session terminated after... (3 Replies)
Discussion started by: vkesineni
3 Replies

7. Shell Programming and Scripting

KSH script -text file processing NULL issues

I'm trying to strip any garbage that may be at the end of my text file and that part is working. The problem only seems to be with the really long lines in the file. When the head command is executed I am directing the output to a new file. The new file always get a null in the 4096 position but... (2 Replies)
Discussion started by: geauxsaints
2 Replies

8. Shell Programming and Scripting

For loop in ksh..Please help..

Hi ALL, I need to take some command line arguments for my script and then want to run a function for each argument.I thought of using for loop as below, but its not working , can some one please help... #!/bin/ksh lpar1=$1 lpar2=$2 lpar3=$3 lpar4=$4 lpar5=$5 echo "$lpar1" >>lpar.txt echo... (4 Replies)
Discussion started by: prashant43
4 Replies

9. Shell Programming and Scripting

while loop issues

Hi guys, Been sifting through these forums for awhile, but never had an account or needed to post. Shoutouts to a great forum with heaps of useful info. Now i consider myself a noob when it comes to linux and to bash scripting. I recently started to learn to use Vmware ESX server which uses... (4 Replies)
Discussion started by: ryath
4 Replies

10. UNIX for Advanced & Expert Users

ksh read bug in HPUX 11i

Is this a bug in ksh on HPUX 11i or is read impromperly documented? INPUT Thu Jan 18 09:14:52 PST : CIFS: Virus Detected - File ONTAP_ADMIN$\vol\vol0\DDD\Ventana\Strattoni\Race Stuff\Rumor.exe in share DDD accessed by client CLIENT (111.11.11.111) running as user USER is infected. The filer... (3 Replies)
Discussion started by: Jackaroe
3 Replies
Login or Register to Ask a Question