You are not logged in.

#1 2018-07-23 08:31:59

markus76
Member
Registered: 2018-07-20
Posts: 2

bash script display multi information

Hi,

I'm creating a bash script that connect to my home server through ssh and it type different command like uptime, ls, and few more. The result going into a variable $test.
After that I would like to display the information from the variable $test but splitted like below and display the information (echo) as well for understand what is it:

the uptime information is:

xxxxxxxxxx

the ls information is:

xxxxxxxxxx

what is the best way to do it?

Thanks

Offline

#2 2018-07-23 08:37:05

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: bash script display multi information

Read up on string manipulation, arrays and printf. Start here: https://mywiki.wooledge.org/BashGuide


Moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2018-07-23 08:40:13

markus76
Member
Registered: 2018-07-20
Posts: 2

Re: bash script display multi information

Thanks

Offline

#4 2018-07-23 13:08:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,543
Website

Re: bash script display multi information

It'd be better to use separate sanely named variables for each bit of information.  Putting all different sorts of information into an array called 'test' will make the script hard to understand, and you will regret that when you look back at it months from now.

Also, is there any reason these data even need to be stored in a variable?  The commands themselves will produce the output:

printf '\nthe uptime information is:\n\n'
uptime
printf '\nthe ls information is:\n\n'
ls

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB