echo doesn't work right


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo doesn't work right
# 8  
Old 03-03-2011
Quote:
Originally Posted by Skrynesaver
The reason I suggested
Code:
which echo

was to see if $PATH is different in your shell and your script. (eg you have a PATH setting in your shell which isn't exported to your script) if the command above returns different values for both then call the command in the script using the full path name returned in the shell, where it worked.
I try that and it turn out to return /bin/echo both

Plus,when I type
Code:
/bin/echo -e "Hello,world\a\n"

in the script ,it work right
Can you tell me why ?

Last edited by Demon; 03-03-2011 at 01:46 PM..
# 9  
Old 03-03-2011
What version of bash do you have? bash --version
# 10  
Old 03-03-2011
Why are you even using echo -e?

Use printf instead.
# 11  
Old 03-03-2011
Hi, Demon:

Quote:
Originally Posted by scottn
Why are you even using echo -e?

Use printf instead.
Amen to what scottn said. You'll see echo in many scripts so you should be familiar with it, but echo with any options is not portable. Do yourself a favor and learn your way around the printf(1) command (usually a shell-builtin).

Regarding your problem, perhaps your environment has aliased echo or has defined a function that overrides the builtin. In bash, the following command would indicate exactly what your shell is trying to execute (whether you type it at the command line or in a script):

Code:
type echo

Regards,
Alister

---------- Post updated at 04:05 PM ---------- Previous update was at 03:58 PM ----------

Quote:
Originally Posted by Demon
Plus,when I type
Code:
/bin/echo -e "Hello,world\a\n"

in the script ,it work right
Can you tell me why ?
When the first word contains slashes, the shell attempts to execute the executable at that location; when the first word does not contain slashes, the shell goes through a lookup process that checks for the existence of functions and builtins before it tries a $PATH lookup. In either case, aliases are expanded beforehand.

Regards,
Alister
# 12  
Old 03-03-2011
Quote:
Originally Posted by Corona688
What version of bash do you have? bash --version
GNU bash, version 4.1.5(1)-release (i686-pc-linux-gnu)

---------- Post updated at 08:09 PM ---------- Previous update was at 07:53 PM ----------

Regarding your problem, perhaps your environment has aliased echo or has defined a function that overrides the builtin. In bash, the following command would indicate exactly what your shell is trying to execute (whether you type it at the command line or in a script):

Code:
type echo

Regards,
Alister

Both return echo is a shell builtin

Plus,when I type the command
Code:
echo --version

in bash it return

--version

when I type
Code:
echo --help

int bash it return

--help

But when I type /bin/echo instead of echo,everything goes right.

Anything difference between the builtin echo and the /bin/echo?

Last edited by Demon; 03-03-2011 at 09:18 PM..
# 13  
Old 03-03-2011
Perhaps you have posix mode and xpg_echo set?

What output do you get from

Code:
 $ shopt xpg_echo

Try setting xpg_echo mode off:

Code:
$ shopt -u xpg_echo

# 14  
Old 03-03-2011
Quote:
Originally Posted by Chubler_XL
Perhaps you have posix mode and xpg_echo set?

What output do you get from

Code:
 $ shopt xpg_echo

Try setting xpg_echo mode off:

Code:
$ shopt -u xpg_echo

The first command return xpg_echo off
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

-ne 0 doesn't work -le does

Hi, I am using korn shell. until ] do echo "\$# = " $# echo "$1" shift done To the above script, I passed 2 parameters and the program control doesn't enter inside "until" loop. If I change it to until ] then it does work. Why numeric comparison is not working with -ne and works... (3 Replies)
Discussion started by: ab_2010
3 Replies

2. Shell Programming and Scripting

Why my awk doesn't work?

root@SDP_Wildcat_Pass-3-C1:~# cat /proc/driver/rtc rtc_time : 05:29:40 rtc_date : 2014-12-19 alrm_time : 01:51:53 alrm_date : 2014-12-20 alarm_IRQ : no alrm_pending : no update IRQ enabled : no periodic IRQ enabled : no periodic IRQ... (4 Replies)
Discussion started by: yanglei_fage
4 Replies

3. UNIX for Dummies Questions & Answers

Why doesn't this work?

find . -name "05_scripts" -type d -exec mv -f {}/'*.aep\ Logs' {}/.LogFiles \; Returns this failure: mv: rename ./019_0120_WS_WH_gate_insideTEST/05_scripts/*.aep\ Logs to ./019_0120_WS_WH_gate_insideTEST/05_scripts/.LogFiles/*.aep\ Logs: No such file or directory I don't know why it's trying... (4 Replies)
Discussion started by: scribling
4 Replies

4. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

5. Shell Programming and Scripting

echo $PWD doesn't work

I have entry in the my .profile like below, but still i see $PWD is not defied in my system export PS1=$LOGNAME@`hostname`':'$PWD'>' echo $PWD also gives me nothing, my env list also give no entry for PWD.Can someone help me setting PWD variable. I use /bin/sh (9 Replies)
Discussion started by: yesmani
9 Replies

6. UNIX for Dummies Questions & Answers

echo $PATH doesn't match $HOME/.profile

This is on a Solaris 9 box, but I feel like a noob, so I am posting here. When I echo $PATH I get a lot of duplicate paths and extra stuff I don't need. What I want is just what I set up in my home dir under .profile My login shell=/bin/bash I checked the following and there are no path... (1 Reply)
Discussion started by: Veestan
1 Replies

7. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

8. UNIX for Dummies Questions & Answers

bash pattern matching echo *[! '/' ] doesn't work

without using ls, just using echo so purely pattern matching I can say echo */ <-- lists directories but how would I match files? surely something like *!/ or * but neither work ? it seems like there isn't much that I can put in but surely i should be able to put any ascii... (1 Reply)
Discussion started by: james hanley
1 Replies

9. Shell Programming and Scripting

Why doesn't this work?

cat .servers | while read LINE; do ssh jason@$LINE $1 done exit 1 ./command.ksh "ls -l ~jason" Why does this ONLY iterate on the first server in the list? It's not doing the command on all the servers in the list, what am I missing? Thanks! JP (2 Replies)
Discussion started by: jpeery
2 Replies
Login or Register to Ask a Question