ash


How to separate fields with pipe character delimiter

社会主义新天地 提交于 2020-01-24 04:13:05
问题 I know this question has already been asked but no of the solution I've found worked for me! I have a program that has an output like this: COUNT|293|1|lps I'm interested in having the second field however no one of these tries worked: ./spawn 1 | cut -d '|' -f2 ./spawn 1 | cut -d \| -f2 ./spawn 1 | awk -F "|" '{print $2}' ./spawn 1 | awk 'BEGIN{FS="|"} {print $2}' ./spawn 1 | sed 's/|/;/g' ./spawn 1 | sed 's/\|/;/g' But the output is always the same: COUNT|293|1|lps Is there a bug somewhere

how to put all command arguments in one variable

天大地大妈咪最大 提交于 2020-01-23 12:05:58
问题 I want to execute a shell script that require 3 arguments. The argument number 2 contains a string with space I want to put all arguments in one variable like this: Linux:~# kk="\"111\" \"222 222\" \"333\"" Linux:~# echo $kk "111" "222 222" "333" Now If I call a function: func() { echo ---$1--- echo ---$2--- echo ---$3--- } with the $kk variable in this way func $kk Then it will return Linux:~# func $kk ---"111"--- ---"222--- ---222"--- And I was expecting to get this result ---111--- ---222

how to put all command arguments in one variable

僤鯓⒐⒋嵵緔 提交于 2020-01-23 12:04:10
问题 I want to execute a shell script that require 3 arguments. The argument number 2 contains a string with space I want to put all arguments in one variable like this: Linux:~# kk="\"111\" \"222 222\" \"333\"" Linux:~# echo $kk "111" "222 222" "333" Now If I call a function: func() { echo ---$1--- echo ---$2--- echo ---$3--- } with the $kk variable in this way func $kk Then it will return Linux:~# func $kk ---"111"--- ---"222--- ---222"--- And I was expecting to get this result ---111--- ---222

Docker Alpine linux running 2 programs

夙愿已清 提交于 2019-12-29 07:11:58
问题 I am trying to create docker image with alpine linux, which after run will create container with 2 running programs. This 2 (in my opinion - I don't know docker well) can't be separated because first program changes the seconds configuration file and then should restart that program too. I am struggling how to run both programs. I have added own script which should run that programs but I am missing something - script is 2 lines on each line is command for running that program - and it only

Can't increment a 0-padded number past 8 in busybox sh

南笙酒味 提交于 2019-12-23 04:24:26
问题 this is the code I am using to save files from a camera and name them from 0001 onward. The camera is running Busybox, and it has an ash shell inside. The code is based on a previous answer by Charles Duffy here. #!/bin/sh # Snapshot script cd /mnt/0/foto sleep 1 set -- *.jpg # put the sorted list of picture namefiles on argv ( the number of files on the list can be requested by echo $# ) while [ $# -gt 1 ]; do # as long as there's more than one... shift # ...some rows are shifted until only

How to match regexp with ash?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 19:28:24
问题 Following code works for bash but now i need it for busybox ash , which apparrently does not have "=~" keyword="^Cookie: (.*)$" if [[ $line =~ $keyword ]] then bla bla fi Is there a suitable replacement ? Sorry if this is SuperUser question, could not decide. Edit: There is also no grep,sed,awk etc. I need pure ash. 回答1: For this particular regex you might get away with a parameter expansion hack: if [ "$line" = "Cookie: ${line#Cookie: }" ]; then echo a fi Or a pattern matching notation +

How does ash files are structured?

跟風遠走 提交于 2019-12-13 16:14:43
问题 I have a small distro (not busybox) that uses ash, and I am not sure how the dot file structure is handled. .ashrc doesnt seem to be picked up nor I see a .bash_profile analog. Is there a default convention for shell startup file? 回答1: This is covered in the Invocation section of the man page. ~/.profile is read for login shells. For non-login interactive shells to read a dotfile at startup, you need to in your environment (ie. set by .profile ) specify the name of a file to read in ENV .

Turning a bash script into a busybox script

点点圈 提交于 2019-12-12 03:30:05
问题 I am working on a device that only has busybox (ash?) and does not support bash. However, I need to run the bash script below on it. Is it possible or busybox simply does not support scripts? #!/bin/bash domain="mydomain.com" record="11019653" api_key="key1234" ip="$(curl http://ipecho.net/plain)" echo content="$(curl \ -k \ -H "Authorization: Bearer $api_key" \ -H "Content-Type: application/json" \ -d '{"data": "'"$ip"'"}' \ -X PUT "https://api.digitalocean.com/v2/domains/$domain/records/

regexp error when filtering command output

家住魔仙堡 提交于 2019-12-11 17:48:39
问题 I want to filter the lines from the following command: $ cat /proc/net/route Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT br-lan 01020300 C0A80101 0003 0 0 3 FFFFFF00 0 0 0 br-lan 03043836 C0A80101 0007 0 0 5 FFFFFFFF 0 0 0 br-lan C0A80100 00000000 0001 0 0 0 FFFFFF00 0 0 0 I want to extract only the line containing the Destination 01020300 and the Mask FFFFFF00 I tried with the following regexp but it does not works cat /proc/net/route | grep "[^ \t\v]\+[ \t\v]\+

How to extract a part of string?

半城伤御伤魂 提交于 2019-12-11 15:47:45
问题 I have string contains a path string="toto.titi.1.tata.2.abc.def" I want to extract the substring which is situated after toto.titi.1.tata.2. . but 1 and 2 here are examples and could be other numbers. In general: I want to extract the substring which situated after toto.titi.[i].tata.[j]. . [i] and [j] are a numbers How to do it? 回答1: You can use cut echo $string | cut -f6- -d'.' 回答2: Pure bash solution: [[ $string =~ toto\.titi\.[0-9]+\.tata\.[0-9]+\.(.*$) ]] && result="${BASH_REMATCH[1]}"

工具导航Map