Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

bash - Cut hex addresses without having them expanded into text

I'm getting a window id with this command and storing it into a variable

id=$(xdo id -n "piper" || xdo id -N "Piper")
echo $id
0x04000007 0x04000001

However, when I try to use cut or head to get only the first address, they convert the hex value to text. For example:

id=$(id | cut -f1 -d' ')
echo $id
uid=1007(user)

I've looked into both cut and head but haven't found any way to make them not (expand?) the hex value. I'd like to get the first value as it is.

question from:https://stackoverflow.com/questions/65910689/cut-hex-addresses-without-having-them-expanded-into-text

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

id (a command) is not the same as ${id} (a variable reference); and id does not return the same thing as xdo ... || xdo ...

Assuming the variable id has your hex codes, and said codes are separated by a space, you can use parameter expansion to pull the first hex code, eg:

$ echo ${id%% *}
0x04000007

## or

$ echo ${id// */}
0x04000007

## or

$ echo ${id// *}
0x04000007

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...