Read file input in while loop does not work on AIX system

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file input in while loop does not work on AIX system
# 1  
Old 10-01-2019
Read file or variable input in while loop does not work on AIX system

I'm working on Aix 6.1 and using ksh shell.

The below works fine on Linux bash or ksh shell [tested both].

while IFS= read -r dirpath ; do
echo "Hi"
done  <<<"$var"

However, any such while loop that reads the input from file or variable using <<< fails on Aix system with the below error:

: syntax error at line 75 : `<' unexpected
Below are the different while loops each having <<< for file input:

while IFS='\n' read -r line; do
while read -r line; do

Can someone please suggest what works for ksh on AiX 6.1 ?

Last edited by mohtashims; 10-01-2019 at 03:56 AM..
# 2  
Old 10-01-2019
ksh does not have the <<< (here string) operator. (An exception are few variants of ksh93.)
In ksh you can do
echo "$var" | 
  while IFS= read -r dirpath
  echo "Hi"

Note that ksh, unlike other shells, runs the last part of a pipe in the main shell. For ex
echo "$var" | 
  while IFS= read -r dirpath
  echo "Hi"
  (( count+=1 ))
echo $count

Other shells run it in a sub shell, so the $count updates are gone when back in the main shell.
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 10-01-2019
@MadeinGermany: I love your answers !! They are precise Smilie

Works fine. I will test more conditions shorlty.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

3. Shell Programming and Scripting

ksh loop to read input until QUIT

Hi I'm looking to write a simple ksh loop reading user input (and write it to a file) until the user enters QUIT at which point I want it to continue. Does anyone have an example of this type of loop? Any help much appreciated Cheers (2 Replies)
Discussion started by: Grueben
2 Replies

4. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

6. Shell Programming and Scripting

ksh while read loop breaks after one record - AIX

#!/bin/ksh for SRV in imawasp01 \ imawasp02 \ imawasp03 \ imawasp04 \ imawasp05 \ imawasp06 \ imawasp07 \ imawasp08 \ imawasp09 do print "${SRV}" while read PASSLINE do SRVNAME=`echo ${PASSLINE} | awk -F\: '{print $1}'` LASTLOGIN=`ssh ${SRV} lsuser ${SRVNAME} | tr '... (2 Replies)
Discussion started by: port43
2 Replies

7. Shell Programming and Scripting

File system creation script on AIX 6.1 using while loop

#!/bin/sh echo "VG: " read VG echo "LP: " read LP echo "SAP: " read SAP echo "NUM: " read NUM echo "SID: " read SID while ]; read VG LP SAP NUM SID ; do mklv -y $SAP$NUM -t jfs2 -e x $VG $LP; crfs -v jfs2 -d /dev/$SAP$NUM -m /oracle/$SID/$SAP$NUM ... (14 Replies)
Discussion started by: arorap
14 Replies

8. Shell Programming and Scripting

read command (input) inside the while loop

Hi, 'read' command is not working inside the while loop, How can I solve this? Rgds, Sharif. (2 Replies)
Discussion started by: sharif
2 Replies

9. UNIX for Dummies Questions & Answers

read user input from within a wile loop that is being fed from below

hi! i need to do a ksh script that uses a wile loop that is fed form below while read line do some things done < myfile inside the while loop i need to read user input to ask the user what he wants to do, but "read" reads the file, and not the standard input while read line do ... (2 Replies)
Discussion started by: broli
2 Replies

10. Shell Programming and Scripting

input inside while read loop

Hi all Does anyone have a script that will allow me to stop inside a while read loop. I want to pause the loop until a enter is pressed. e.g. While read line do echo something if LINECOUNT > 40 then read ENTER?"PRESS ENTER TO CONT..." ... (3 Replies)
Discussion started by: jhansrod
3 Replies
Login or Register to Ask a Question

Featured Tech Videos