#1.1. Read the file into an array, with each line as an element.
IFS=$'\r\n';
# arr=(`cat /etc/lsb-release`)
arr=(`< /etc/lsb-release`)
#2.2. Print out all array elements
for t in "${arr[@]}";do echo $t;done
unset IFS
-------output----------
#1.1. Read the file into an array, with each line as an element.
# arr=(DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS")
#2.2. Print out all array elements
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
|
#1.1. Read the file into an array, with each line as an element.
open ($fh, glob("/etc/lsb-*"));
@lines = <$fh>;
close $fh;
#2.2. Print out all array elements
print @lines;
# or use one liner
print do { open ($fh, glob("/etc/lsb-*")); <$fh>;};
# or use File::Slurp
# use File::Slurp;
# @lines = read_file(glob('/etc/lsb-*'));
-------output----------
#1.1. Read the file into an array, with each line as an element.
#2.2. Print out all array elements
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
# or use one liner
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
# or use File::Slurp
# use File::Slurp;
# DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
= read_file(glob('/etc/lsb-*'));
|
import glob
fob = open("/etc/lsb-release",'r')
arr = fob.readlines()
for i in arr: print i,
fob.close()
-------output----------
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"
|