Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with "here-string" in ksh

Status
Not open for further replies.

jrb1tx

Programmer
Oct 21, 2011
2
US
I have a simple script:

echo $SHELL
read test1 test2 test3 <<< "test1 test2 test3"
echo $test1 $test2 $test3

When I run it, I get:

/bin/ksh
test1 test2 test3

However, when I add line 1:

#!/bin/ksh

Now I get:

/bin/ksh
./test[3]: syntax error: `< ' unexpected

What's going on?
 
Hi

There will be some mistake around the shell invocation.

The [tt]<<<[/tt] ( here-string ) syntax is Bash-only, so your first code was probably executed by Bash. For example my login shell is Bash and when I start MKsh by typing [tt]mksh[/tt] at the Bash prompt, then an [tt]echo $SHELL[/tt] in MKsh will still display /bin/bash. Some ways to check the shell ( note the mentioned [highlight]misleading[/highlight] output ) :
Code:
[blue]master[/blue] # echo $SHELL
/bin/bash

[blue]master[/blue] # echo $0
bash

[blue]master[/blue] # ps $$
  PID TTY      STAT   TIME COMMAND
 7643 pts/16   Ss     0:00 bash

[blue]master[/blue] # mksh

[green]master[/green] # echo $SHELL
[highlight]/bin/bash[/highlight]

[green]master[/green] # echo $0
mksh

[green]master[/green] # ps $$
  PID TTY      STAT   TIME COMMAND
 7722 pts/16   S      0:00 mksh

Feherke.
 
That clears up my confusion. I added a "ps" to my script and see that the actual shell being run is "sh".

The data I want is actually in a variable so I'm going to try something like:

read test1 test2 test3 <<EOF
$mydata
EOF

Thanks for the quick response!
 
Another alternative...
Code:
#!/bin/ksh

MYDATA="test1 test2 test3"

print $MYDATA | read VAR1 VAR2 VAR3

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top