Bash script: Store w3m dump into variable

335 Views Asked by At

How to store w3m dump result into a variable in a bash script? The result I got by w3m dump is
C: randomIP randomPORT randomUSERNAME randomPASSWORD
I want to cut "C:" and store everything else into variables so I can add it into a file.

2

There are 2 best solutions below

3
Devavrata On

You can store any bash command output in this manner:-

var=$(command) # replace command by w3m dump command
#Later you can replace first occurring of C: by sed
var=$(echo $var | sed s/^C://)

Now var variable will consist of dump without "C:".

2
Julien Lopez On
<your command> | read useless var1 var2 var3 var4

As explained in man read, read will (big surprise!) read a line on standard input (hence the pipe) and assign the given variables one by one using the IFS (by default the space character) as a delimiter in the input.

So in your example, useless will be assigned to "C:"; var1 to "randomIP"; ...