This work under simple shell
cd `mktemp -d` &&>'c'a't'
ln -s /proc/loadavg /proc/uptime .
Then now
procs=$(*)
echo $procs
0.30 0.08 0.03 1/612 31671 322787.60 1259967.99
Nota: Of course, >cat
could be written >$(echo -e \\0143\\0141t)
Care, from there, you could encouter some issues due to Locales!
Goto last demo using LC_ALL=C
Same way:
mv cat grep
mv loadavg Mem
ln -s /proc/meminfo Zdatas
rm uptime
mems=$(*)
echo $mems
MemTotal: 16386788 kB MemFree: 9816320 kB MemAvailable: 12144892 kB
or worst...
mv grep sed
mv Mem s+\\\(Mem\\\|Swap\\\).\*\:++p\;d
then
memsw=$(*)
echo $memsw
16386788 kB 9834080 kB 12163596 kB 0 kB 20971516 kB 20971516 kB
So simple is this!
declare -p procs mems memsw
declare -- procs="0.14 0.12 0.05 1/612 32078
324221.56 1265616.26"
declare -- mems="MemTotal: 16386788 kB
MemFree: 9832212 kB
MemAvailable: 12161688 kB"
declare -- memsw=" 16386788 kB
9834080 kB
12163596 kB
0 kB
20971516 kB
20971516 kB"
Last test using LANG=C
(or not)
cd `mktemp -d` &&>'c'a't'
ln -s /proc/meminfo zdatas
cp c* y+-+-+\;s+\\\(Mem\\\|Swap\\\).\*\:\ \*++p\;d
rename 'y/act/esd/' ???
*
may render something like
378908 kB
31940 kB
217924 kB
0 kB
102396 kB
102396 kB
Or
cd `mktemp -d`
ln -s +++\;s+\\\(Mem\\\|Swap\\\).\*\:\ \*++p\;d /proc/me*o ed .
rename 's/^/chr(113+(20>length?1.3*length:8))/e' *
*
what shell is the is
sh
and what shell allows thisfor
syntax? it is expressly allowed inzsh
. – mikeserv – 2015-12-23T19:55:40.463@mikeserv Bash. I remember reading somewhere that this syntax was allowed in some old
sh
and that Bash also allows it because of that, though sadly I don't have a citation. – Digital Trauma – 2015-12-23T19:57:47.840ahh...
csh
, probably - that's how they worked in that shell. – mikeserv – 2015-12-23T20:02:47.397by the way, in
ksh93
the above thing could be :;{1..10}
, and inbash
:printf %s\\n {1..10}
– mikeserv – 2015-12-23T20:08:17.7931
for((;i++<10)){ echo $i;}
is shorter thanfor i in {1..10};{ echo $i;}
– Evan Krall – 2017-01-19T04:58:08.560for((;${#r}>i++;)){ echo ${r:i-1:1};}
iterates over each character of a string$r
– roblogic – 2019-03-23T12:27:59.727