Tag Info

Hot answers tagged

28

There's checkbashisms. On Debian, it's shipped as part of the package maintainer tools. Test your scripts under dash and posh. Both have a few non-POSIX constructs, but if your script works in both, it's likely to work in most places. (With the caveat that it's difficult to test typical shell scripts as they tend to have a lot of corner cases.) If you ...


12

That's not the Bourne shell, or bash emulating the Bourne shell, that's the Almquist shell, in your case probably the Debian Almquist shell (a Linux fork by Debian of BSDs' sh itself based on the original Almquist shell). In the Almquist shell (the original one and the modern versions), % is used in PATH for extra features specific to ash. Quoting from the ...


7

Lookarounds are perl regex features. GNU grep implements them (with the -P option). I cannot say whether any busybox command does. In this case though, you're just looking for the work after "on". Choose one of echo "$TEST" | awk '{for (i=1; i<=NF; i++) if ($i == "on") {print $(i+1); break}}' echo "$TEST" | sed ...


7

The short answer is no, they're not 100% compatible. But most the shells are pretty close to the basic, so you would only rarely bump into inconsistencies. In fact, most shells differ not much by added syntax, but by some extra features like tab-completion and similar. Also, dash is sort of a descendant of ash - or port from BSD to linux, to be precise. ...


3

[TL,DR: use the urlencode_grouped_case version in the last code block.] Awk can do most of the job, except that it annoyingly lacks a way to convert from a character to its number. If od is present on your device, you can use it to convert all characters (more precisely, bytes) into the corresponding number (written in decimal, so that awk can read it), ...


3

This error message comes from ash. There are several shells with a similar syntax. Ash is a relatively basic one designed for a small memory footprint and fast execution. Another common shell is Bash. Bash has more features. The syntax you posted exist only in bash (and some other shells, but not ash). In ash, you would need to write¹: day=5 while [ $day ...


2

Perhaps GRASS GIS pre-defines a variable named "day"? The code doesn't work in straight bash by the way. You don't actually increment the value of "day". #!/bin/bash for (( day=5; day<367; day=day+5 )); do # commands that I've tested without a loop. echo $day done exit 0 That works for me, bash 2.05b on a RHEL 5.0 server.


2

I understand ash to be Bourne-derived, so I think this should work: if ping -c1 www.google.com > /dev/null; then echo "It worked" else echo "No dice" fi


2

Ash doesn't have regular expressions, but it has shell wildcard matching. You need to use case, wildcard matching isn't available via test a.k.a. [ … ]. There is no way to express the regex [a-zA-Z]* using wildcards, but you can perform the same test in two steps, one for the first part and one for the second part. case "$x" in ...


1

I don't really understand your question, what's the actual question? First you are stating that you can access the history via the fc builtin and then you are asking if the shell implements a history? Furthermore, the man page states: The number of previous commands that can be accessed are determined by the value of the HISTSIZE variable. and A ...


1

You're misinterpreting the output. It's just that those files (cmdline, environ...) are not terminated by a newline character. So for instance, if /proc/pid/cmdline contains xxx, cat /proc/pid/cmdline will output xxx, but because there's no newline character (which the terminal discipline converts on output to CRLF) the cursor will not go back to the ...


1

Would this work better? for day in $(seq 5 5 367); do # commands echo $day done



Only top voted, non community-wiki answers of a minimum length are eligible