excuse me but I am a beginner and can't imagine how to solve my puzzle in Linux shell scripting.
I have the file. File with name /etc/hostname or environment variable $HOSTNAME in my case in this file is wroten RxPower-1 or TiPower-1
How I can get the first part RxPower or TiPower to use it later as an environment variable. I try to use awk but without success. Sorry for my bad English but this is not my mother language.
awk -F"-" '{if ($1=="RxPower") mm=$1;else mm=TiPower}' /etc/hostname
thank you Advance for your help !!
CodePudding user response:
Using sed
to export the variable
$ export var1=$(sed 's/\([^-]*\).*/\1/' /etc/hostname)
or using awk
$ export var1=$(awk -F"-" '{print $1}' /etc/hostname)