LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 09-27-2010, 11:56 PM   #1
henrtm05
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Rep: Reputation: 0
Setting a variable


This is from a previous post

here is a link to the previous post. http://www.linuxquestions.org/questi...ommand-834518/

I am trying to set this command to a variable, I think it is not working because I am running a command within a command.

This is the command

grep "\:`grep ^mygroup /etc/group | cut -d: -f3`\:" /etc/passwd

I tried doing

fristgrp=`grep "\:`grep ^mygroup /etc/group | cut -d: -f3`\:" /etc/passwd`

but it just hangs and does nothing.

Any help would be appreciated thanks.
 
Old 09-28-2010, 12:19 AM   #2
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,159
Blog Entries: 4

Rep: Reputation: 149Reputation: 149
Hi If i am not wrong you want to grep the output of :
Quote:
grep ^mygroup /etc/group | cut -d: -f3
Suppose that group is root;then

Quote:
grep ^root /etc/group | cut -d: -f3
; will give output

Quote:
0
Now if you grep 0

Quote:
grep 0 /etc/passwd
it gives output;

Quote:
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0perator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
mysql:x:27:480:MySQL Server:/var/lib/mysql:/bin/bash
qemu:x:107:107:qemu user:/:/sbin/nologin
smolt:x:490:474:Smolt:/usr/share/smolt:/sbin/nologin
i.e it lists all 0 like 107;480 etc.

What i am trying to say is if your group id is 111 then it will give even 1, 12 or 32 or 212 etc

So change the way you are using commands;better write script!
 
Old 09-28-2010, 12:24 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Nesting backticks "`" will not work. Also I don't think you should escape the colons.

Does the following work?

Code:
fristgrp=$(grep ":$(grep ^mygroup /etc/group |cut -d: -f3):" /etc/passwd)
echo $fristgrp
Evo2.
 
Old 09-28-2010, 01:18 AM   #4
henrtm05
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Original Poster
Rep: Reputation: 0
This worked for me thanks.
 
  


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
environment variable setting chii-chan Linux - General 5 01-23-2009 07:29 PM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM
Setting an environmental variable maevious Linux - Newbie 6 11-24-2005 04:15 PM
Setting up a environment variable Hiper1 Linux - Newbie 3 03-08-2005 08:43 AM
About setting DISPLAY variable Rex_chaos Linux - General 4 09-29-2003 01:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:13 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
Open Source Consulting | Domain Registration