I have a robotframework test which I am producing the output in the below format. I intentionally tried export
so I can set them as bash environment variable to be used later.
How do I achieve this?
Command:
robot -d output cli.robot | grep -i -e "id1" -e "id2"
here
VAR1=id1 VAR2=id2
Output out of that is:
export VAR1=cfdsgbds4r4ew43vf
export VAR2=34-sdggs4fsz9vrfg
these values of id1 and id2 are the ones that are being assigned to VAR1 and VAR2.
My Goal is to be able to do just that. I don't want that output above to be saved to any file
echo $VAR1
echo $VAR2
If the variables are safe to use and you are sure that the output is safe and will not incidentally format your hard drive and erase all data, you may use eval
with a process substitution:
eval "$(robot ... | grep ...)"
export VAR1="$id1" # ie. after edit
export VAR2="$id2"
just like docker-machine env
or ssh-agent . Be sure to read eval command and security issues .
A way better, safer way and also requiring more work is to write your own parser for the data, tokenize and extract names and values of variables from the output and assign and export them yourself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.