LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-24-2006, 09:13 AM   #1
madhugp
LQ Newbie
 
Registered: May 2006
Posts: 20

Rep: Reputation: 0
linux shell program problem plz


hi, in shell program,
how to mix up message with a command result.

i.e i want to get the following line.

echo "copying xyz file size 50m"

here 50m is the size of the file
comes from ls -sh xyz command.
how to mixup these two into single line.
thanks
 
Old 12-24-2006, 09:20 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Put the command you're using between backticks, e.g.

echo "copying xyz file size `ls -sh xyz`".

Last edited by Nylex; 12-24-2006 at 10:01 AM.
 
Old 12-24-2006, 07:58 PM   #3
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 25, 26, RHL 5.2
Posts: 560

Rep: Reputation: 56
Just to expand on what Nylex mentioned. This is called command substitution and there are two forms `command` or $(command). Both work equally well. If you have to nest commands it is a little easier to use the second form. I like the second one a little more because I can see it easier in the script. It's just a preference thing.

Bill

Last edited by wmakowski; 12-24-2006 at 07:59 PM.
 
Old 12-25-2006, 10:22 AM   #4
madhugp
LQ Newbie
 
Registered: May 2006
Posts: 20

Original Poster
Rep: Reputation: 0
nor working plz

I used, echo " copying file 'ls -sh xyz'"

but is displaying the same above , but not
ls -sh command result.

plz help





Quote:
Originally Posted by wmakowski
Just to expand on what Nylex mentioned. This is called command substitution and there are two forms `command` or $(command). Both work equally well. If you have to nest commands it is a little easier to use the second form. I like the second one a little more because I can see it easier in the script. It's just a preference thing.

Bill
 
Old 12-25-2006, 10:53 AM   #5
whk
Member
 
Registered: Jun 2005
Posts: 202

Rep: Reputation: 37
It's the back tick. The upper left button with the tilde(~) and grave accent ( ˋ )
and not the single quote(').

However, this is another work around:
echo; echo -n "copying file size "; echo `ls -sh xyz.sh`; echo

hth

Last edited by whk; 12-25-2006 at 11:35 AM.
 
  


Reply



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
linux shell program problem beanxp Programming 2 11-17-2006 03:36 PM
Problem running C++ program in Linux Shell Alkibiades Programming 17 10-28-2006 06:51 AM
Problem with mandrake's konsole shell...Plz HELP madiyaan Linux - Newbie 5 05-11-2003 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:12 PM.

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
Open Source Consulting | Domain Registration