Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-14-2015, 10:46 PM   #1
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
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,418

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
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 '\'
printf "\"NA\" \"\\\t\"%.0s" {1..4}

"NA" "\t""NA" "\t""NA" "\t""NA" "\t"

"NA" "\t""NA" "\t""NA" "\t""NA" "\t"[chris@boole lq]$ 

"NA" "\t"
1 members found this post helpful.
Old 10-14-2015, 11:29 PM   #3
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.

Old 10-15-2015, 12:27 AM   #4
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


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:31 AM.

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