LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 05-13-2013, 09:17 PM   #1
maddyfreaks
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,093

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
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
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,093

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
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
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,010

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
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
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,010

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
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
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,010

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
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
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,010

Rep: Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004Reputation: 1004
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
LQ Newbie
 
Registered: May 2011
Posts: 29

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
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,010

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

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
LQ Newbie
 
Registered: May 2011
Posts: 29

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


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using xargs drpartha Linux - Software 4 10-27-2012 11:32 AM
xargs: unmatched single quote; by default quotes are special to xargs unless you use Raakh5 Linux - Newbie 4 03-23-2012 04:37 PM
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


All times are GMT -5. The time now is 07:12 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration