LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-15-2013, 12:05 AM   #16
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,453

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116

Having re-read post #8 a few times,
Code:
#show k file
 cat k.sh

some
rubbish
alias myloc=blah

# show get alias file
cat get_alias.sh

a=$(grep myloc k.sh)
#echo $a
eval $a
If we now source get_alias.sh, the alias gets set into the curr env
Code:
. ./get_alias.sh

# use alias cmd to see curr aliases
 alias
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias myloc='blah'
You just need to make those your *rc files instead.
 
1 members found this post helpful.
Old 05-15-2013, 12:44 AM   #17
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 6,237

Rep: Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660Reputation: 1660
Quote:
Originally Posted by maddyfreaks View Post
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... ??
I'm afraid, xarg will not do the job because it opens a new shell and all the commands will be executed inside that environment. The current shell will remain unchanged. In such cases you can try eval too, but it can be also dangerous
 
Old 05-15-2013, 07:29 AM   #18
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,938

Rep: Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798
I'm not quite sure what you want, but this will extract a line containing "myloc" fromthe given file and source that line in the current shell:
Code:
. <(grep myloc ~spadmin/.profile)
You might want to note that aliases are, by default, expanded only in interactive shells. If you have scripts where you want to use any aliases, you would need to set the expand_aliases option in each such script, and that is a fairly dangerous thing to do unless you can strictly limit the aliases that are in effect.
 
2 members found this post helpful.
Old 05-15-2013, 07:55 AM   #19
maddyfreaks
Member
 
Registered: May 2011
Posts: 55

Original Poster
Rep: Reputation: 0
Thanks Chris. Your output helped me and solved my problem.

You guys are amazing.
 
Old 05-15-2013, 09:13 PM   #20
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,453

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
Thx
Actually, rknichols' answer is slicker, mine probably shows the detail/concepts a bit more.
 
  


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
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


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