variable value return of multiple command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variable value return of multiple command
# 1  
Old 09-05-2011
variable value return of multiple command

I wrote this script

Code:
#!/bin/bash

var=`du -sch /var/log/messages;du -sch /var/log/maillog`
echo $var

I am getting result as follows.
Code:
# sh my.sh
2.1M /var/log/messages 2.1M total 296K /var/log/maillog 296K total

I need it like below
Code:
2.1M /var/log/messages 
296K /var/log/maillog

Can anyone help?
# 2  
Old 09-05-2011
try echo -e $var

--ahamed
# 3  
Old 09-05-2011
Try the following:
Code:
var=`du -h /var/log/messages /var/log/maillog`
echo -e $var

Well, the above doesn't work( I should test before I post ) but this should:
Code:
var=`du -h /var/log/messages /var/log/maillog`
printf "%s %s\n" $var


Last edited by xbin; 09-05-2011 at 05:50 PM.. Reason: third edit is the charm
# 4  
Old 09-05-2011
Thanks xbin, your second code worked fine. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Carriage return with cat variable

Hi, I wish to know how to works the carriage return with cat.. As a picture often speaks better than words, my code below : #te=`cat text.txt` (I tried this, but the same..) te=$(cat text.txt) echo $te My file text.txt below: BLABLABLABLABLALBLA BLABLABLABLABLALBLA ... (9 Replies)
Discussion started by: Arnaudh78
9 Replies

2. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

3. Shell Programming and Scripting

How to store the return value of a command into a variable?

I want to store the return value of grep -c string filename into a variable, say count. How do I do that? For example if grep -c "string" "filename" shows 0 on executing it in the sh shell then I want to store this 0 in a variable. Is it possible? :D (5 Replies)
Discussion started by: navienavnav
5 Replies

4. Shell Programming and Scripting

Need Multiple Return Values

Hi, I need to retrun multiple values function errorFileCreation { echo "Before" return -1 "Siva"; echo "Aftyer" } echo ${?} - This can be used to getting first value. how can i get second one. Advance Thanks... Shiv (3 Replies)
Discussion started by: rsivasan
3 Replies

5. Shell Programming and Scripting

Can $? return multiple values?

Hi, I have a script which does something like the below: execute_some_script.sh $arg1 $arg2 `exec-some-cmd` if then; do something else do something else fi However, during some cases, there is an error saying: line xxx: [: too many arguments at the line number which has... (5 Replies)
Discussion started by: laloo
5 Replies

6. Shell Programming and Scripting

Awk return variable

Hi I have 2 working script, now i'd like to get the return value from the first and give it to the 2 script (both script work correctly if I run it separately). so i think the problem is only the first line in the way i pass the variable. in the final the "print lst", is just to check the... (2 Replies)
Discussion started by: Dedalus
2 Replies

7. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

8. Shell Programming and Scripting

Return code of command assigned to variable

How do I evaluate the result of a command assigned to a variable?? Example: var1=`cmd` rc=$? rc will be the result of the assignment rather than cmd since it executes after. How do I evaluate the result of the command itself? Cheers..:confused: (2 Replies)
Discussion started by: browndr
2 Replies

9. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

10. Shell Programming and Scripting

Return Code of multiple inner executions

Need some clarification on two topics and I apologize for the long post. Topic 1). I have a PERL script which sends output to the console. This is executed like a daemon script. I would like to capture the "print" commands of the script to a log file. How can this be done. Topic 2) Within the... (9 Replies)
Discussion started by: jerardfjay
9 Replies
Login or Register to Ask a Question