Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Differences in BASH and ASH shells regarding if command? Post 302452173 by Corona688 on Thursday 9th of September 2010 12:55:35 PM
Old 09-09-2010
ASH is of course extremely limited, though it's amazing for what it is: Its source code is smaller than the compiled binaries of some other shells.

I thought globbing that way was a bash-ism but it seems to work in ksh too. Interesting.

I'd use string operations instead of glob-matching to test if a variable resides inside another in ASH. Replace the matching part with nothing, and if the resulting string is smaller, then it must have matched.

Code:
$ NEEDLE="ert"
$ HAYSTACK="quwertyuiop"
$ T="${HAYSTACK/${NEEDLE}/}"
$ echo $T
quwyuiop
$ if [[ "${#T}" -lt "${#HAYSTACK}" ]]
then
        echo "NEEDLE is in HAYSTACK"
fi
NEEDLE is in HAYSTACK
$


Last edited by Corona688; 09-09-2010 at 01:59 PM.. Reason: more quotes igor!
 

10 More Discussions You Might Find Interesting

1. BSD

BSD, Bash and Shells?

When I use Mac OS X's Terminal the UI is some what easier than that of Linux... I this just a shell or something because using Bash is a pain in RH's Linux 9. It's so sensitive about case etc. ??? In that way what is the shell that OS X uses as it's default Bash is on OS X (OK Duh) and... (3 Replies)
Discussion started by: RedVenim
3 Replies

2. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

3. Shell Programming and Scripting

Interacting with two BASH shells

Hi. I'm working with two BASH shells in order to perform two tasks. For simplicity, suppose that at Shell #1 I'm executing this program: sleep 100 whose PID is 263. Meanwhile Shell #2 is waiting for its termination to follow with a second one. I tried with: wait 263 # Script for second... (4 Replies)
Discussion started by: hresquivelo
4 Replies

4. Shell Programming and Scripting

Bash shells communication

Hello all, I have the following problem. In a Bash shell I run a program (I don't have the source code) which will execute some steps. At every step the program will wait for a user input. So I would like that another script which is running on a different shell will send these input togheter with... (4 Replies)
Discussion started by: alohisius
4 Replies

5. Shell Programming and Scripting

Differences between shells

What is the practical difference among the different shell like csh , ksh , bash etc.:confused::confused: Please use descriptive subjects instead of single words (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

6. Shell Programming and Scripting

ash busybox read command not working inside function....

I have a script that has to execute a read command in a function, this is in an ash busybox. The code is... trapcatch () { echo "Ctl-c Detected, what do you want to do?" echo "Please choose the number of one of the following options" echo "1. Jump past this Set" echo "2. Exit... (8 Replies)
Discussion started by: tesser
8 Replies

7. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

8. Ubuntu

Bash to Ash, errors and adjustments

I wrote Bash script and now I want to convert it to Ash. One headache is this function: do_adduser() { setaddprompt _arr_add=("Add manually" "Add via TXT" "return to main menu" "exit program") select add_action in "${_arr_add}" do case "$REPLY" in 1)... (7 Replies)
Discussion started by: fzivkovi
7 Replies

9. Ubuntu

Bash to ash port, character-matching problem

I'm trying to convert this working bash script into an Ash script, read -p "Username:" _username if ! ]]; then echo "Valid" else echo "INVALID" fi However, Ash does not recognize the "=~" character. How can I do this? Also, is there a good reference guide, so I... (5 Replies)
Discussion started by: fzivkovi
5 Replies

10. Ubuntu

Convert a bash to ash

hello everybody, i'm a beginner in ash and i want to convert this bash script to ash. this script send a xml file to a nagios server : #!/bin/bash PROGNAME=$(basename $0) RELEASE="Revision 0.3" print_release() { echo "$RELEASE" } print_usage() { echo "" echo "$PROGNAME... (6 Replies)
Discussion started by: mdijoux25
6 Replies
ematch(8)							       Linux								 ematch(8)

NAME
ematch - extended matches for use with "basic" or "flow" filters SYNOPSIS
tc filter add .. basic match EXPR .. flowid .. EXPR := TERM [ { and | or } EXPR ] TERM := [ not ] { MATCH | '(' EXPR ')' } MATCH := module '(' ARGS ')' ARGS := ARG1 ARG2 .. MATCHES
cmp Simple comparison ematch: arithmetic compare of packet data to a given value. cmp( ALIGN at OFFSET [ ATTRS ] { eq | lt | gt } VALUE ) ALIGN := { u8 | u16 | u32 } ATTRS := [ layer LAYER ] [ mask MASK ] [ trans ] LAYER := { link | network | transport | 0..2 } meta Metadata ematch meta( OBJECT { eq | lt |gt } OBJECT ) OBJECT := { META_ID | VALUE } META_ID := id [ shift SHIFT ] [ mask MASK ] meta attributes: random 32 bit random value loadavg_1 Load average in last 5 minutes nf_mark Netfilter mark vlan Vlan tag sk_rcvbuf Receive buffer size sk_snd_queue Send queue length A full list of meta attributes can be obtained via # tc filter add dev eth1 basic match 'meta(list)' nbyte match packet data byte sequence nbyte( NEEDLE at OFFSET [ layer LAYER ] ) NEEDLE := { string | c-escape-sequence } OFFSET := int LAYER := { link | network | transport | 0..2 } u32 u32 ematch u32( ALIGN VALUE MASK at [ nexthdr+ ] OFFSET ) ALIGN := { u8 | u16 | u32 } ipset test packet against ipset membership ipset( SETNAME FLAGS ) SETNAME := string FLAGS := { FLAG [, FLAGS] } The flag options are the same as those used by the iptables "set" match. When using the ipset ematch with the "ip_set_hash:net,iface" set type, the interface can be queried using "src,dst (source ip address, out- going interface) or "src,src" (source ip address, incoming interface) syntax. CAVEATS
The ematch syntax uses '(' and ')' to group expressions. All braces need to be escaped properly to prevent shell commandline from inter- preting these directly. When using the ipset ematch with the "ifb" device, the outgoing device will be the ifb device itself, e.g. "ifb0". The original interface (i.e. the device the packet arrived on) is treated as the incoming interface. EXAMPLE &; USAGE # tc filter add .. basic match ... # 'cmp(u16 at 3 layer 2 mask 0xff00 gt 20)' # 'meta(nfmark gt 24)' and 'meta(tcindex mask 0xf0 eq 0xf0)' # 'nbyte("ababa" at 12 layer 1)' # 'u32(u16 0x1122 0xffff at nexthdr+4)' Check if packet source ip address is member of set named bulk: # 'ipset(bulk src)' Check if packet source ip and the interface the packet arrived on is member of "hash:net,iface" set named interactive: # 'ipset(interactive src,src)' AUTHOR
The extended match infrastructure was added by Thomas Graf. iproute2 6 August 2012 ematch(8)
All times are GMT -4. The time now is 11:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy