INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

echo everything as it is

echo everything as it is

(OP)

Hello,

I am looking for a reliable solution to echo (from a ksh script) everythin as it is given to the echo command (avoiding any variable intepreting in case some exists and also signs like ' , " etc. )...

I want to avoid using "\" before every e.g. $ sign ...

is it possible use any brackets combination to achive this?
or maybe some dedicated echo_function () in a script?

I found that :

cat < EOF
$V
EOF

return value of variable, but:

cat < "EOF"
$V
EOF

doesn't.

I tried following function but it doesn't do what is expected:

CODE

$ cat ./printline.ksh
my_echo () {
cat << EOF
$*
EOF
echo $*
}

echo 11111111:
my_echo /usr/bin/perl -n&#$45234i !!!-e '$_ =~%34 /^aaaaaaaa/ ) { print \"%#$""""'''````#$_\"}  else {print}' ffffff
grep 45234i $0|sed s/^my_echo\ //g

echo 22222222:
my_echo /usr/bin/perl -#223mnnni -e '''''!!!''$_ =~#@2424""" /^cc"""/ ) { print \"#$_\"}  else {print}' %%%%%%%%%%%%%%%%%%%%%5
grep 223mnnni $0|sed s/^my_echo\ //g
$ ./printline.ksh
11111111:
/usr/bin/perl -n&#$45234i !!!-e '$_ =~%34 /^aaaaaaaa/ ) { print \"%#$""""'''````#$_\"}  else {print}' ffffff
grep 45234i $0|sed s/^my_echo\ //g
22222222:
/usr/bin/perl -n
/usr/bin/perl -n
/usr/bin/perl -#223mnnni -e !!!$_ =~#@2424""" /^cc"""/ ) { print \"#$_\"}  else {print} %%%%%%%%%%%%%%%%%%%%%5
/usr/bin/perl -#223mnnni -e !!!$_ =~#@2424""" /^cc"""/ ) { print \"#$_\"} else {print} %%%%%%%%%%%%%%%%%%%%%5
/usr/bin/perl -#223mnnni -e '''''!!!''$_ =~#@2424""" /^cc"""/ ) { print \"#$_\"}  else {print}' %%%%%%%%%%%%%%%%%%%%%5
grep 223mnnni $0|sed s/^my_echo\ //g
$ 

RE: echo everything as it is

What about this ?

CODE --> ksh

my_echo () {
sed -n "s![^#]*my_echo $1 #!!p" $0
}
cat $0
echo 11111111:
my_echo 1 #/usr/bin/perl -n&#$45234i !!!-e '$_ =~%34 /^aaaaaaaa/ ) { print \"%#$""""'''````#$_\"}  else {print}' ffffff

echo 22222222:
my_echo 2 # /usr/bin/perl -#223mnnni -e '''''!!!''$_ =~#@2424""" /^cc"""/ ) { print \"#$_\"}  else {print}' %%%%%%%%%%%%%%%%%%%%%5 

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: echo everything as it is

(OP)
hello,

your proposal works, but I would like to avoid the numbering in each function execution ($1) and then sed every time script ($0).

I was thinking about universal function in a script I could use anywhere in it which will do the trick just running (example):

my_echo /usr/bin/perl -n&#$45234i !!!-e '$_ =~%34 /^aaaaaaaa/ ) { print \"%#$""""'''````#$_\"} else {print}' ffffff

and this will output all what is on the right side of the function execution (of course without the fist space after the function execution).


kind regards,

RE: echo everything as it is

I don't know how you could bypass the shell expansion mechanism ...

RE: echo everything as it is

(OP)

maybe another workaround somone could please forvide for my "issue"

I need to log to a file complete command name which is being executed from this script followed by the stdout/stderr which this command produces (the second part of this I achieve using tee -a )

thx in advance for any hint

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close