LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-13-2013, 09:17 PM   #1
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Rep: Reputation: 0
Help Needed Regarding Xargs


Hi team,

You folks are helping me in learning Shell script. This is the problem I am facing. Currently I have an alias which will change for every host
$ cat ~sapadmin/.profile | grep myloc
alias myloc='cd /export/nfs1-34/`

I have my own .bashrc file which i will use and i cant load them so i tried to do some stuff in my file.. using xargs but am not able ... All i need is when i do that cat the alias should get executed.

cat ~sapadmin/.profile | grep myloc | xargs; ---No Luck;

Can some one please help me ... It can be done any ways no restriction of xargs ... that was my thought.
 
Old 05-13-2013, 11:47 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. this looks like you've got a single quote (') at the start, then a backquote (`) at the end.
They should both be single quotes.
Code:
alias myloc='cd /export/nfs1-34/`
2. This
Quote:
I have my own .bashrc file which i will use and i cant load them
is unclear; please re-write differently

3. aliases aren't 'executed'; they are set into your env, so that when you type 'myloc', you get the associated cmd executed.

Can you clarify what you are trying to achieve?
 
Old 05-13-2013, 11:51 PM   #3
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
Chris - this is want I want to do
I want to grep myloc from .progile then I should set my alias

How do u do that in one shot grep and set your alias
 
Old 05-14-2013, 01:34 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you put it in your .bash_profile (assuming your shell is bash), then its set for you at login.
(similarly for .profile)

Check your shell
Code:
echo $SHELL

grep <your user> /etc/passwd
 
Old 05-14-2013, 01:39 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can manually "import" settings from a file using source:
Code:
source <this is the filename>
# and now you can use your alias
myloc
# that's all
----------------------------------
# also 
# do not write:
cat ~sapadmin/.profile | grep myloc
# but
grep myloc <filename>
# next time
 
Old 05-14-2013, 07:23 AM   #6
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
As said mine is different requirement
When I source by .bashrc file it should set the alias . Since alias myloc
Is different for each host so I have my .bashrc which is unique
So when I source .bashrc I should get the myloc info from .profile and
It should be set in .bashrc

Hope this understands my requirement
 
Old 05-14-2013, 07:26 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
no, I'm sorry, I do not understand. Can you show us .bashrc? What is the difference?
 
Old 05-14-2013, 07:32 AM   #8
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
Our default shell is ksh so we are using .profile and we set alias myloc in .profile on
Thousands of hosts. I like bash so I am planning to create my own .bashrc
Which will remain unique I.e get the values from .profile

So people will set alias myloc in .profile since I don want to edit my .bashrc
On each host I like to get that value from .profile and getting executed when I source .bashrc

How can I do it
 
Old 05-14-2013, 07:37 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can create a new file in .bashrc (from .profile) containing what you need and source that file
 
Old 05-14-2013, 07:53 AM   #10
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
I can't because we have 1223 systems so I want to have unique .bashrc
So I can pull to all hosts
 
Old 05-14-2013, 07:56 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you misunderstood
into .bashrc you can instert a small function or similar to create a temporary file containing what you need and also you can source that file
 
Old 05-14-2013, 07:59 AM   #12
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
Just need your thoughts on how to execute the output after cat and grep
 
Old 05-14-2013, 08:01 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
TMPFILENAME=whatever
cat or grep or sed or whatever > $TMPFILENAME
source $TMPFILENAME
 
Old 05-14-2013, 10:56 AM   #14
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
But i am looking something to be on the fly instead writing everything into a tempfile.

Just asking ... cant we ask xarg to execute that alias command as soon as we get it with cat & grep ??

Any other options... ??
 
Old 05-14-2013, 10:04 PM   #15
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
Can someone help me please
 
  


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
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 7 05-21-2014 07:26 PM
Using xargs drpartha Linux - Software 4 10-27-2012 11:32 AM
Using xargs SBN Linux - General 2 04-07-2008 07:44 PM
`wc`, `xargs` h/w Programming 11 09-30-2007 04:22 PM
xargs yawe_frek Linux - Software 1 04-15-2007 04:26 PM

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

All times are GMT -5. The time now is 04:23 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