[BusyBox 0000697]: ash strstr command built-in

bugs at busybox.net bugs at busybox.net
Tue Feb 7 18:16:52 UTC 2006


A NOTE has been added to this issue. 
====================================================================== 
http://busybox.net/bugs/view.php?id=697 
====================================================================== 
Reported By:                nawawi
Assigned To:                BusyBox
====================================================================== 
Project:                    BusyBox
Issue ID:                   697
Category:                   New Features
Reproducibility:            always
Severity:                   feature
Priority:                   normal
Status:                     assigned
====================================================================== 
Date Submitted:             02-07-2006 07:58 PST
Last Modified:              02-07-2006 10:16 PST
====================================================================== 
Summary:                    ash strstr command built-in
Description: 
add c-syntax strstr feature to ash shell.
if success return 1 else return 0.

example:

if strstr "i like cat" "cat"; then
  echo "found cat"
fi

strstr "i like cat" "cat"
if [ $? = 1 ]; then
 echo "found cat"
fi
====================================================================== 

---------------------------------------------------------------------- 
 vodz - 02-07-06 08:05  
---------------------------------------------------------------------- 
My bash have not this builtins command.
Also. You really sure use putchar('0') vs printf("0\n")? 

---------------------------------------------------------------------- 
 nawawi - 02-07-06 10:16  
---------------------------------------------------------------------- 
1) this function use for busybox ash shell you can test with busybox ash
enabled

./busybox ash <script file>

script file:

if [ $(strstr "this is test" "test") = 1 ]; then
 echo "found test"
else
 echo "not found"
fi

2) Im used putchar coz just need to print the return value stdout
   eg; strstr "this is test" "test" will print to stdout as 1

3) also you can use code below for bash & ash scripting

strstr() {
	[ "$1" = "$2" ] && return 0
	slice=${1#*$2*}
	[ "$slice" = "$1" ] && return 1
	return 0
}

if strstr "this is test" "test" ; then
  echo OK
fi 

Issue History 
Date Modified   Username       Field                    Change               
====================================================================== 
02-07-06 07:58  nawawi         New Issue                                    
02-07-06 07:58  nawawi         Status                   new => assigned     
02-07-06 07:58  nawawi         Assigned To               => BusyBox         
02-07-06 07:58  nawawi         File Added: ash.c.patch                      
02-07-06 08:05  vodz           Note Added: 0001059                          
02-07-06 10:16  nawawi         Note Added: 0001060                          
======================================================================




More information about the busybox-cvs mailing list