[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I'm new to linux and particularly using shell scripts. On

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 11
Thread images: 2

File: Screenshot_20170704-223758.png (70KB, 1080x1920px) Image search: [Google]
Screenshot_20170704-223758.png
70KB, 1080x1920px
I'm new to linux and particularly using shell scripts. On my android, i'm trying to use mem.sh to output total amount of free memory + swap. I think one error is how the variables are defined but I don't know how to rectify this.when run as a script, it outputs error in screenshot. I understand why, but can't figure out how to resolve it. Help from someone more intelligent than me please?
>>
Nevermind then, sorry.
>>
It's a syntax error. Problem is that you can't just do this:
< (free -m)


Bash sees the ( token and doesn't understand what the fuck you mean. Perhaps you were trying to do shell interpolation, in which case you should have prefixed it with a $ character. So it should look like $(command args) instead of (command args)
>>
>>61221402
Process substitution <(free -m) isn't available in sh.

Seeing the shebang, #!/bin/bash, you have to either execute it with ./mem.sh (if you enabled executable bit with chmod +x mem.sh) or do bash mem.sh instead of sh mem.sh
>>
>>61221829
see http://tldp.org/LDP/abs/html/process-sub.html
>>
>>61221402
You can also get around the issue by piping to awk instead of making it read from a file:

free -m | awk '/^Swap/ {print $4}'
>>
>>61221854

Hrm... then maybe OP is using an outdated version of Bash that does not support this? I know Android ships with Busybox, which is pretty shitty. If you want a good shell on Android, you pretty much have to use Termux.
>>
>>61221981
This is in Termux, I'm just not great at this. With >>61221847 solution, error message 'ambigious redirect' comes up.
Have not yet tried >>61221884
>>
File: Screenshot_20170704-234354.png (154KB, 1080x1920px) Image search: [Google]
Screenshot_20170704-234354.png
154KB, 1080x1920px
Thanks for your help, I've found a solution for what I needed using >>61221884 . I was trying to get the script to output total free memory for klwp, but could not use the code in screenshot to do so, so needed to use a script. Thankfully, >>61221884 s solution works fine in klwp :)
>>
>>61222122

*in original screenshot
>>
>>61221829
>>61221981

If you're uncertain about the advice you are giving, remove the trip. You have no notoriety.
Thread posts: 11
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.