---
# System prepended metadata

title: Linux Script Note

---

# Linux Script Note

## Check if string contains substring

### For Bash

```bash
str="Hello, this is script" 
if [[ "$str" == *"script"* ]]; then
  echo "Find script"
else
  echo "Cant find script"
fi
```

### For Sh

```sh
str="Hello, this is script" 
result=$(echo $str | grep -i "script")
if [ $result  ]; then
    echo "Find script"
else
    echo "Cant find script"
fi
```

## Script read variable

### For buildroot, post_image.sh

 in `make file` execute by this

```makefile
target-post-image: $(TARGETS_ROOTFS) target-finalize
	@$(foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT)), \
		$(call MESSAGE,"Executing post-image script $(s)"); \
		$(EXTRA_ENV) $(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))
```

`BR2_ROOTFS_POST_IMAGE_SCRIPT` mean location of **post_image.sh**

`foreach s, $(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT))`  mean  substitute `$(call qstrip,$(BR2_ROOTFS_POST_IMAGE_SCRIPT))` to `s`

so `$(s) $(BINARIES_DIR) $(call qstrip,$(BR2_ROOTFS_POST_SCRIPT_ARGS))$(sep))`

mean `$BR2_ROOTFS_POST_IMAGE_SCRIPT $BINARIES_DIR $BR2_ROOTFS_POST_SCRIPT_ARGS`
<br>

in **post_image.sh**

variable `$1=$BINARIES_DIR `, `$2=$BR2_ROOTFS_POST_SCRIPT_ARGS`

<br>

in most case, `BR2_ROOTFS_POST_SCRIPT_ARGS`is `"xgs-iproc-arm32"`.

then variable `$1=$BINARIES_DIR `, `$2="xgs-iproc-arm32"`
  <br>
Sometimes, `BR2_ROOTFS_POST_SCRIPT_ARGS`may be `"arm64 helix5"  `

then variable `$1=$BINARIES_DIR `, `$2="arm64"`, `$3="helix5"`

get variable by each space ' '.
