Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-17-2008, 06:29 AM
|
#1
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637
Rep:
|
Script: how to assign values to variables using "awk" results?
I want to write a script to find out the journal size of an ext3 file system. I have two commands (graciously provided by unSpawn):
Code:
The journal is located at inode:
'tune2fs -l /dev/device | awk '/Journal inode/ {print $3}''
The size is:
debugfs -R "stat <inodenumber>" /dev/device 2>&1| awk '/Size: / {print $6}'|head -1
These commands work okay from the command line. I wanted to do something like
Code:
#!/bin/bash
#first parameter is the device name [s|h]dxy
inode='tune2fs -l /dev/device | awk '/Journal inode/ {print $3}''
#and noticed that that won't work.
# nor will
echo "Journal Size: "
debugfs -R "stat <inode>" /dev/$1 2>&1| awk '/Size: / {print $6}'|head -1 >1
Hm. So how can I get the value awk is printing in the first statement loaded into a variable (e.g. inode), and how would the second command print the journal size to the screen?
http://www.tldp.org/LDP/Bash-Beginne...e.html#chap_03 left me stumped...
|
|
|
11-17-2008, 06:34 AM
|
#2
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,418
|
Use backquotes(`) not single quotes(') to run a cmd and save the result thus:
var=`cmd`
echo $var
|
|
|
11-17-2008, 06:37 AM
|
#3
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637
Original Poster
Rep:
|
Aha. I'll try that this evening and be back with the result.
Anybody about why printing the results from within the script doesn't work? Can it be done less clumsily?
|
|
|
11-18-2008, 01:59 AM
|
#4
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,637
Original Poster
Rep:
|
Yep, works. After some thought, I even remembered why , thanks chrism01.
I solved the other question by the same method, i.e. put the statement in back ticks and assigned the value to a variable (yes, I know I could put them out with "echo" but later on I want to calculate the byte value into MBs, so...).
Last edited by JZL240I-U; 11-24-2008 at 08:50 AM.
|
|
|
All times are GMT -5. The time now is 07:42 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|