Sponsored Content
Full Discussion: while read issue
Top Forums Shell Programming and Scripting while read issue Post 302700161 by bakunin on Thursday 13th of September 2012 04:52:28 AM
Old 09-13-2012
Quote:
Originally Posted by cfajohnson
There is nothing in the script that is shell or OS specific, so the shell and the OS are both irrelevant.
Across implementations in different OSes ksh might either be ksh88 or ksh93, which exhibit differences regarding the treatment of "echo". Furthermore, if "/bin/echo" is found in the PATH, ksh treats its own built-in differently, even if it is there. With bash the situation may or may not be that complicated, but i lack experience with all bash-implementations there may be, so i can't say for sure.

Therefore my opinion is that knowing the OS and the shell thread-opener talks about may or may not matter. I can only decide once i know these, not beforehand.

Quote:
In all shells, echo adds a newline.
In some shells "echo" is not a built-in but a call to "/bin/echo". If the implentation of each respective OS does or doesn't add a newline i don't know. I haven't used each and every Unix-like system there is.

Quote:
Neither echo nor print is a good idea.

Use printf; it is the only portable method.
With Korn shell "print" is a built-in and is preferred. (see here) With bash "echo" is a built-in and is probably preferred too (not so sure as i don't use bash more than i have to, but most bash scripts i have seen use "echo" for that purpose).

To ask for "portability" in general without specifying where you would want to port it is completely arbitrary: in general it is a good idea to write scripts in a way so that they work on as many systems as possible with as few changes as possible. To ask for a ksh script that it has to work in bash (or vice versa) makes about as much sense as asking for a FORTRAN program to compile on a C-compiler without error.

Again, i don't say portability should not be an issue. But "portability" as a goal makes only sense if there is a reference platform/shell/environment defined to which it should be portable. Without such a definition it is just a buzzword.

Probably you imply POSIX as this reference here and mean "portability towards the POSIX-specification", which is as good a goal as any else. If the thread-opener has POSIX-compatible systems and might face the necessity to port the script from one of these POSIX-compatible systems to another then you are right - on the other hand, if he has another set of systems he might be better off to enforce compatibility between the systems he actually has than towards a generic standard some of his systems do not adhere to.

Insofar it would also be a good idea to know more about his actual environment instead of declaring this "irrelevant" like above.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

While read issue...

I think I saw another post where someone said he an issue with a 'while within a while' but there were no solutions on it. I have an input file of data columns separated by pipes "|" and I want to set each column to a variable and do something with it. This I can do. When I get to a certain... (5 Replies)
Discussion started by: giannicello
5 Replies

2. Shell Programming and Scripting

While loop read line Issue

Hi I am using while loop, below, to read lines from a very large file, around 400,000 rows. The script works fine until around line 300k but then starts giving incorrect result. I have tried running the script with a smaller data set and it works fine. I made sure to include the line where... (2 Replies)
Discussion started by: saurabhkumar198
2 Replies

3. Shell Programming and Scripting

Multi Line 'While Read' command issue when using sh -c

Hi, I'm trying to run the following command using sh -c ie sh -c "while read EachLine do rm -f $EachLine ; done < file_list.lst;" It doesn't seem to do anything. When I run this at the command line, it does remove the files contained in the list so i know the command works ie... (4 Replies)
Discussion started by: chrispward
4 Replies

4. UNIX for Advanced & Expert Users

read() from ttyS1 issue while write() is Ok

Hi! I've got a problem with reading from serial port, when I run this code on Digi ConnectCore Wi-9c. But writing to serial port is Ok. By the way, when I'm running this code on "full" Linux it is working Ok - I can read and write to serial without mistakes. Where is a problem? uname -a:... (3 Replies)
Discussion started by: Japonomatj
3 Replies

5. Shell Programming and Scripting

while read LINE issue

Hi, This is the script and the error I am receiving Can anyone please suggest ? For the exmaple below assume we are using vg01 #!/bin/ksh echo "##### Max Mount Count Fixer #####" echo "Please insert Volume Group name to check" read VG lvs |grep $VG | awk {'print $1'} > /tmp/audit.log ... (2 Replies)
Discussion started by: galuzan
2 Replies

6. Shell Programming and Scripting

Issue in using read keyword twice

Hi, I have a situation where i need to read line by line from a text pad and with each line , i need to take inputs from command line and do some process. Using below code i am not able to use 'read' keyword twice. Can any one please help cat > t.txt a d c > cat > t.ksh while read... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

7. Shell Programming and Scripting

Read line, issue with leading - and {}'s

Heyas With my forum search term 'issue with leading dash' i found 2 closed threads which sadly didnt help me. Also me was to eager to add the script, that i didnt properly test, and just now figured this issue. So i have this code: if ] then while read line do line="${line/-/'\-'}"... (7 Replies)
Discussion started by: sea
7 Replies

8. Shell Programming and Scripting

ksh while read issue

Hello, I have used a chunk of ksh script similar to this in many places without any issue: while : do print; read OPTION?"Enter a number (q to quit): " expr ${OPTION} + 1 >/dev/null 2>&1 CHECKVAL=$? if }" != ${OPTION} ]; then ... (2 Replies)
Discussion started by: port43
2 Replies

9. Shell Programming and Scripting

File read format issue in UNIX

hi all. my loop is getting failed eventhoug it is 1=1 but it is failure message. any help plz Output expected : echo "sucesss" code out=`cat bit.txt` if ]; then echo "sucess" else echo "Failure" (2 Replies)
Discussion started by: arun888
2 Replies

10. Shell Programming and Scripting

While read pipe input issue

Hello, I have an ffmpeg bash script which is working nice and I need to do the same for other sources. To create new scripts and to deal with multiple bash files sounds not logical. It is a bit hard to manage for me.. I wondered if it was possible to make my input file as variable. Then I... (1 Reply)
Discussion started by: baris35
1 Replies
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.10 30 Jan 2004 script(1)
All times are GMT -4. The time now is 05:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy