Issue
I have writen a bash file like this:
JSESSIONID=$(curl -I 'http://17....212' \
-H 'Accept: text/h...b3;q=0.7' \
-H 'Accept-Language: zh...8' \
-H 'Cache-Control: ma...0' \
-H 'Connection: k...ve' \
-H 'Upgrade-Insecure-Requests: 1' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36' \
--insecure|grep -o -e "JSESSIONID=\(.*\); P"|sed "s/JSESSIONID=//g"|sed "s/; P//g")
echo $(JSESSIONID)
(Apostrophe is for privacy)
I want to get JSESSIONID, I can run it in the command-line, and it will return a pure string: The JSESSIONID. However, I dont know how to assign it to a variable. By using the code above, it will shows:
/etc/rc.common: line 37: JSESSIONID: not found
I know this question is very basic, but I have searched for a long time and have not found a workable answer.
have tried to switch "$()" to "``", But it is useless.
Solution
JSESSIONID already contain result of execution your command. You don't need to run it again with command substitution.
For getting value use
echo "${JSESSIONID}"
or
echo "$JSESSIONID"
Answered By - Neo Lip Answer Checked By - Candace Johnson (WPSolving Volunteer)