Advertisement

commands to variables UNIX

Started by November 18, 2006 12:13 PM
5 comments, last by Sander 17 years, 10 months ago
Is there anyway to convert a command into a variable. This is what I figured would work. However, it doesn't
Quote: let capital = 'cut -d: -f1 finalD.ca'
I'm trying to assign the output from 'cut' into a variable. this is how the file FinalD.ca looks (there's only one line in the file).
Quote: something:29342:20329
That's all that's in the file. Why doesn't let capital = 'cut -d: -f1 finalD.ca' Work? Any help would be appreciated.
in bash try this instead:
capital = $(cut -d: -f1 finalD.ca)
:wq!
Advertisement
at the top of my script I've got

#!/bin/sh

and when I try

capital = $(cut -d: -f1 finalD.ca)

I get an error: "command capital" not found.
sorry, remove the white space around the equal sign:
capital=$(cut -d: -f1 finalD.ca)
:wq!
Wow... You just made life a lot less complicated for me :)

and for that I respect you.

You can also do it like this:
MYVAR=`ls`echo $MYVAR

Note that Im not using the single quotes ' but the other kind `
(dont know what it is called)
Advertisement
They're called backticks. It's the thingy below the ~ on a regular US qwerty keyboard.

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement