LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2015, 10:46 PM   #1
bison72
LQ Newbie
 
Registered: May 2012
Posts: 8

Rep: Reputation: Disabled
Giving wrong output with sh but correct output with command entry in Ubuntu


Hi there,

I want to execute the command as below using sh:
printf '"NA" [slash]"\\t"[modulus].0s' {1..4}

PS: Sorry I have to put a "modulus" and "slash" up there because the symbols are missing in the message.

which will give output as below that I want:
"NA" "\t""NA" "\t""NA" "\t""NA" "\t"

I could execute the file using sh in Fedora. However, when I run sh in Ubuntu, it shows the incorrect output below:
"NA" [slash]"\t[slash]"

When I execute the command, it could give exactly what I want.

This happens in Ubuntu but not in Fedora. Anyone has any idea how to fix this?

Thanks in advance.

Last edited by bison72; 10-14-2015 at 11:00 PM.
 
Old 10-14-2015, 11:16 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
I think on Ubuntu sh is symlinked (or replaced ?) with dash.
On my Centos, which should probably be the same as Fedora, both 'sh' and 'bash' work, although I did have to add one more '\'
Code:
printf "\"NA\" \"\\\t\"%.0s" {1..4}

bash t1.sh 
"NA" "\t""NA" "\t""NA" "\t""NA" "\t"

sh t1.sh 
"NA" "\t""NA" "\t""NA" "\t""NA" "\t"[chris@boole lq]$ 

dash t1.sh 
"NA" "\t"
HTH
 
1 members found this post helpful.
Old 10-14-2015, 11:29 PM   #3
bison72
LQ Newbie
 
Registered: May 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi Chris,

Appreciate your help. It works with bash but not with sh or dash. I wrote the script in Fedora and this is the first time I execute it in Ubuntu.

Rgds,
Louis
 
Old 10-15-2015, 12:27 AM   #4
serverpoint.com
Member
 
Registered: Oct 2015
Posts: 52

Rep: Reputation: 6
Hi Louis,

Can you confirm this by running the command below. What is the output?

ls -la /bin/sh
 
  


Reply

Tags
fedora, sh, ubuntu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Redirecting output to a file is giving wrong result ankitpandey Programming 11 12-14-2012 12:13 AM
Giving output of a command as the input to another whirlpool Programming 5 09-07-2010 04:31 PM
[SOLVED] append command output to file by giving command in terminal sumeet inani Linux - Newbie 4 07-03-2009 11:36 AM
Bash Scripting POSIX Class [[:alnum:]] giving wrong output livetoday Linux - Newbie 3 01-22-2008 12:56 AM


All times are GMT -5. The time now is 11:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration