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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo everything as it is 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL

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
$

 
What about this ?
Code:
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
FAQ181-2886
 
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,
 
I don't know how you could bypass the shell expansion mechanism ...
 

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
 
Did you try the set -x command ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top