LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-28-2010, 12:56 AM   #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, 01:19 AM   #2
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,138
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
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, 01:24 AM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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, 02:18 AM   #4
henrtm05
LQ Newbie
 
Registered: Sep 2010
Posts: 11

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


Reply


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


All times are GMT -5. The time now is 09:26 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration