Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Not getting expected output

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-07-2013
scriptor scriptor is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 13 May 2015, 11:33 PM EDT
Posts: 103
Thanks: 10
Thanked 0 Times in 0 Posts
Not getting expected output

Hi

I have written below script to get the data in table form.

Code:
#!/bin/sh
echo "File Name\tType"
for i in *;
do
echo "$i\t\c"
if [ -d $i ]; then
echo "directory"
elif [ -h $i ]; then
echo "symbolic link"
elif [ -f $i ]; then
echo "file"
else
echo "unknown"
fi
done

however i am getting output in different way . pls see below

Code:
sel1 \t\c
file
t1 \t\c
file
t1.txt \t\c
file
test \t\c
file
test1 \t\c
file
true.tar \t\c
file
vk \t\c
directory

i also noticed that the command
Code:
echo "File Name\tType"

is not working properly in script but when i run this separately it is working fine .

Code:
$ echo "File Name\tType"
File Name       Type
$

i am using ksh shell

regards,
Scriptor
Sponsored Links
    #2  
Old Unix and Linux 01-07-2013
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 4 April 2015, 12:03 PM EDT
Posts: 3,060
Thanks: 34
Thanked 660 Times in 639 Posts
try with -e

Code:
echo -e "$i\t\c"

Sponsored Links
    #3  
Old Unix and Linux 01-07-2013
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 22 May 2015, 6:54 PM EDT
Location: Zürich
Posts: 8,552
Thanks: 337
Thanked 1,075 Times in 934 Posts
Quote:
Originally Posted by itkamaraj View Post
try with -e

Code:
echo -e "$i\t\c"

Yuk!

Use printf instead.
    #4  
Old Unix and Linux 01-07-2013
scriptor scriptor is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 13 May 2015, 11:33 PM EDT
Posts: 103
Thanks: 10
Thanked 0 Times in 0 Posts
thx itkamaraj this helps

but why the same command behave differently ?
regards,
Scriptor
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Output is not comming as expected Agupte Shell Programming and Scripting 8 03-26-2012 07:44 AM
elif if not expected kmsekhar Shell Programming and Scripting 12 12-30-2011 06:35 AM
awk not generating the expected output scripter12 Shell Programming and Scripting 7 09-14-2010 09:43 PM
[C language] system function print output when not expected. ejdv Programming 5 05-04-2010 02:09 PM
Why this is not working in expected way? meharo Shell Programming and Scripting 4 12-07-2009 08:47 AM



All times are GMT -4. The time now is 10:43 PM.