• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A newbie unix question, xargs

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jane Jukowsky
Ranch Hand
Posts: 157
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic