The second option is close, but you don't need to escape anything,
because there are no nested identical quotes, and you are not trying
to pass shell magic symbols (&, |, etc) as parameters -- except for
the '$10' which you correctly enclose in single quotes so that the
shell passes literal $10, rather than the substituted value.

DISKTEMP=$(smartctl -A /dev/sdc | grep Temperature_Celsius | awk '{print $10}')

I prefer to use $(...) rather than backticks `...` to capture stdout
from a command pipeline into a shell variable.

Stephen Irons


On 14 October 2015 at 13:41, Bryce Stenberg <[email protected]> wrote:
> Hello again,
>
> This is sort of following on from my previous post.
>
> I have this command below to give me the temperature of hard drive 3 which 
> works from command line:
>
> smartctl -A /dev/sdc | grep Temperature_Celsius | awk '{print $10}'
>
>
> but I'm having trouble getting it to run in a bash script file assigned to a 
> variable.
>
> In a script I've tried escaping the pipe symbols and the quotes but nothing 
> seems to quite work...
>
> DISKTEMP=smartctl -A /dev/sdc \| grep Temperature_Celsius \| awk \'{print 
> $10}\'
>
> DISKTEMP=$(smartctl -A /dev/sdc \| grep Temperature_Celsius \| awk \'{print 
> $10}\')
>
>
> It seems a simple enough task, can someone please show me how it should be 
> written?
>
> Thanks,
>   Bryce Stenberg.
> _______________________________________________
> Linux-users mailing list
> [email protected]
> http://lists.canterbury.ac.nz/mailman/listinfo/linux-users
_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users

Reply via email to