Is this a typo in my Book?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Is this a typo in my Book?
# 22  
Old 05-05-2012
That is indeed possible in bash en ksh93, and it is faster too, but in POSIX this can only be done with cat..
# 23  
Old 05-06-2012
Yes. It is unfortunate POSIX doesn't include this ksh syntax. I also just noticed bash implements it a slightly different way, i.e. requires quotes where ksh doesn't.
Code:
$ cat "a b"
data
$ cat s
file="a b"
echo $(<$file)
$ ksh88 s
data
$ ksh93 s
data
$ bash s
s: line 2: $file: ambiguous redirect

As expected, other POSIX and non POSIX shells have various behaviors:
Code:
$ /usr/xpg4/bin/sh s
data
$ dash s

$ sh s
s: syntax error at line 2: `(' unexpected
$ pdksh s
data
$ zsh s
data

# 24  
Old 05-06-2012
Interesting. This appears to apply to any redirect:
Code:
cat < $file

In bash this gives an ambiguous redirect
In ksh this works.

The bash version is more consistent with how things would usually work in shell, but IMO the ksh way is more logical in the sense that a variable reference can only ever mean one thing in this case, since a redirect to/from two files will never make sense (nor be allowed) anyway.

So I guess there is yet another reason to always use double quotes around a variable reference: portability.
Code:
cat < "$file"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Programming

Which C++ book do you recommend?

Hello, May be my post may look naive to many...but it isn't if you were to believe me.After, trying to learn programming in C for at least 5 years , I concluded that K & R is the best book to learn C, alas I took a lot of time to realize this. So, I'm going to start learning how to program... (8 Replies)
Discussion started by: blackwhite
8 Replies

2. Shell Programming and Scripting

Typo in sample script from book?

Hello, I'm new to this forum, and I apologize in advance if I did something wrong here. I am pretty stumped here as I am still getting the error message, "./comc1.sh: test: argument expected." after executing the script itself. Here's the script file I modified: I tried executing line 4... (1 Reply)
Discussion started by: ConcealedKnight
1 Replies

3. Solaris

Typo in man file??

Hi is it me or is there a typo in the Sun Solaris man page for ps. I thought the option for listing a process by PID was just -p but on the clearcase server at work it reads: - -ps proclist Lists only process data whose process ID numbers are given in proclist.... (5 Replies)
Discussion started by: steadyonabix
5 Replies

4. Shell Programming and Scripting

BASH Command Line Typo -- Can't Get Out

Hi Sorry to post a bit of an "I'm an idiot" post, but I did a typing error and typed "ls 'l" instead of "ls -l". This seems to have made me enter some sort of mode or other that I can't seem to be able to get out of. The new line prompt is > (if that helps). Sorry for posting such a... (1 Reply)
Discussion started by: Viola
1 Replies

5. Solaris

e-book

Hi everybody I a new one And I have just wanted to research on Sun Solaris So can you help me what e-book to read ( and if can you give me the direct address to load ) Thks so much (3 Replies)
Discussion started by: iwbasts
3 Replies
Login or Register to Ask a Question