wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes A newbie unix question, xargs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "A newbie unix question, xargs" Watch "A newbie unix question, xargs" New topic
Author

A newbie unix question, xargs

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Sorry if this forum is not meant for simple questions like this, but why does not this work for me on Ubuntu?

hostname | xargs -I {} export HOSTNAME={}

says:

xargs: export: no such name or directory


export alone works fine.

Am I overengineering it? How can I make an environment variable with host name in it?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

You've got me puzzled on this one. HOSTNAME is already defined on most distros.

Also xargs is used primarily in conjunction with multi-file operations. For example, when Eclipse hangs when restarting, this command can often fix it:


If HOSTNAME isn't defined, you should be able to do so like this:



Which I think is the way the login script does it.

The reason xargs had problems with the "export" directive is because export is an internal shell command, and not an actual program. If you use the "which" command to try and locate it, it will come up not found.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Thanks for the info. The backtick characters, right! I forgot. BTW, is there a Windows equivalent for backticfks?


Tim Holloway wrote:
The reason xargs had problems with the "export" directive is because export is an internal shell command, and not an actual program. If you use the "which" command to try and locate it, it will come up not found.



That gets me confused. Why would not an internal shell command work? I thought it will execute anything after the substitution?




Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

Jane Jukowsky wrote:Thanks for the info. The backtick characters, right! I forgot. BTW, is there a Windows equivalent for backticfks?


Tim Holloway wrote:
The reason xargs had problems with the "export" directive is because export is an internal shell command, and not an actual program. If you use the "which" command to try and locate it, it will come up not found.



That gets me confused. Why would not an internal shell command work? I thought it will execute anything after the substitution?






an internal shell command is not a program. It's a directive to the shell itself. If you wanted it in Windows terms, there's no such file as "export.exe" - it's just a function of the "bash.exe" program (or whichever shell you're using).

Instead the shell recognizes the command and interprets it directly when it's issued as a command. But in this case, the command was "xargs", and "export" was merely seen as data. The man pages for xargs have some things to say about the fact that by default xargs doesn't fire up a sub-shell to execute commands, although they might confuse more than help.
 
 
subject: A newbie unix question, xargs
 
Similar Threads
Remove some files recursively
How to search text based content from home directory using find or grep?
Unix scripting question - Reading directories
how to list info of more than one jar.
using exec in find, awk? xargs?