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.
Asked
Active
Viewed 308 times
0

Albert Karlsson
- 1
- 2
2 Answers
0
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:".

Devavrata
- 1,785
- 17
- 30
-
Now I have only the text I want, but how to assign randomIP randomPORT randomUSERNAME randomPASSWORD to variables? Thanks! – Albert Karlsson Mar 23 '16 at 15:01
-
I got it to work with IFS=" " set $var echo $1 echo $2 echo $3 echo $4 – Albert Karlsson Mar 23 '16 at 15:13
-
yeah you can `cut` command to separate a line. You can use some thing like this:- `echo 'randomIP randomPORT randomUSERNAME randomPASSWORD' | cut -d' ' f1` for getting `randomIP`. Similarly `f2` for 2nd argument and so on. – Devavrata Mar 24 '16 at 10:40
0
<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"; ...

Julien Lopez
- 1,794
- 5
- 18
- 24
-
While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. - [From review](https://stackoverflow.com/review/low-quality-posts/11741816) – Ferrybig Mar 23 '16 at 12:20
-
Quite true. Besides, I realize that my here string was pointless here, a pipe will suffice. I added some explanations but my solution is straightforward now. Thanks. – Julien Lopez Mar 23 '16 at 12:36