Sponsored Content
Top Forums Shell Programming and Scripting "<< Unmatched" in ksh script using sftp Post 302229961 by shabeer on Thursday 28th of August 2008 08:49:20 AM
Old 08-28-2008
An Exmple to resolve the `<<' unmatched" issue in KSH

Hi All,

The final SFTP program can look like this;

sftp -b - server-1 <<-EOF
get /root/restore/$each.tar
bye
EOF

Describing the above program with the (space)/(no-space)/(no-characters) characters to make it more clear to understand the code; (space) means either a whitespace / a tab.

sftp -b - server-1(space)<<-EOF(no-space)(no-characters)
(space)get /root/restore/$each.tar(space)
(space)bye(space)
(no-space)(no-characters)EOF(no-space)(no-characters)
-------------------------------------------

In addition, here is some sample programs for you to test; Hope with this you may undestand the usage of "heredocument". It's better always use a '-' after << and before the first CONTENT tag

Program 1

RESULT="`sqlplus $USER/$PWD@$TNS <<-CONTENT
select sysdate from dual;
exit;
CONTENT
`";
echo "$RESULT"

Never add any other characters to the second tag (Eg:- Never do this [ CONTENT`";]. You will get error.

Describing the above program with the (space)/(no-space) characters;

RESULT="`sqlplus $USER/$PWD@$TNS(space)<<-CONTENT(no-space)
(space)select sysdate from dual;(space)
(space)exit;(space)
(no-characters)(no-space)CONTENT(no-space)(no-characters)
(space)`";(space)
echo "$RESULT"

-----------------------------------------------------------

Program 2

cat <<-CONTENT
echo "Hello Foo"
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"
CONTENT

Describing the same program with the (space)/(no-space) characters;

cat(space)<<-CONTENT(no-space)
(no-space)echo "Hello Foo"(no-space)
(no-space)echo "Hello"; Hello "Foo";(no-space)
(space)(space)CONTENT(no-space)
(no-space)CONTENT"(no-space)
(no-space)CONTENT(no-space)

Only the Final CONTENT will match with the First CONTENT tag. Others have either a whitespace / a character attached to it and the KSH will not be able to recognise it, because it considers the whole as a string which doesn't match with the string CONTENT.

Output of the above program
echo "Hello"; Hello "Foo";
CONTENT
CONTENT"


To Conclude the CONTENT tag should not be attached with any characters including white space. Always use the '-' afterthe << and before the first CONTENT tag
Eg:-

cat <<-CONTENT
resolved
CONTENT

Description

cat(space)<<-CONTENT(no-space)(no-characters)
(space)(space)(space)(space)resolved(space)(space)(space)(any-characters)
(no-characters)(no-space)CONTENT(no-space)(no-characters)

Result follows;

resolved

Smilie

Last edited by shabeer; 08-28-2008 at 11:07 AM..
This User Gave Thanks to shabeer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh script as a login shell return "no controlling terminal"

I have created a ksh shell script and used it as a login shell for a user. </etc/passwd> lramirev:x:111:200:Luis:/export/home/menush:/usr/local/menush/menush My shell script is like this: </usr/local/menush/menush> #!/bin/ksh # if ] then . $HOME/.profile fi ... (8 Replies)
Discussion started by: lramirev
8 Replies

2. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

3. Shell Programming and Scripting

"else" unmatched error in shell script.

Friends I have pasted a script below d08083: cat tests #!/bin/ksh if then rm -r Last-Previous mv Previous Last-Previous mv Current Previous mkdir Current #cd Current mv $1 Current else cd Current mv "$1\$2" Current\*\ fi (4 Replies)
Discussion started by: Renjesh
4 Replies

4. Shell Programming and Scripting

Ksh script function, how to "EXIT 2" without killing the current process?

Hi, Using AIX 5.3 and Ksh. />ls -al /usr/bin/ksh -r-xr-xr-x 5 bin bin 237420 Apr 10 2007 /usr/bin/ksh /> I recently started working for a new employer. I have written UNIX K-Shell scripts for many years and have never had this particular issue before. Its perplexing me. I have... (2 Replies)
Discussion started by: troym72
2 Replies

5. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, I´ve already searched the forum but can´t find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

6. Shell Programming and Scripting

ksh script that echo " please insert your name " and store the output to a login.log file.

Hello All Nice to meet you all here in this forum, it's my 1rst time here i'm asking about a little issue that i face i added a ksh script that echo " please insert your name " and store the output to a login.log file. the script is working fine with normal telnet but Xstart is not working... (8 Replies)
Discussion started by: islam.said
8 Replies

7. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

8. Shell Programming and Scripting

Irritating Shell script problem - " unmatched

Hi, I have the below KSH shell script: #!/usr/bin/ksh if ; then echo "Usage: resourceSts <server> else if ; then source="<server>" ssh <userid>@$source > output 2>/dev/null <<_EOF scstat -g _EOF elif ; then source="<server>" ssh... (5 Replies)
Discussion started by: chris01010
5 Replies

9. Shell Programming and Scripting

How to fix this "Input is not UTF-8" while executing ksh script?

Hi, I have an automated script which have set of sqls but when i am trying to execute the automated script by using nohup command, it is throwing an error like "Input is not UTF-8" . And when i digged in to it, i am getting some "Â" character in the shell script. How to avoid this!? Thanks. (1 Reply)
Discussion started by: Samah
1 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
All times are GMT -4. The time now is 01:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy