ash

Set expand_alias when shopt not available?

混江龙づ霸主 提交于 2021-02-10 15:28:13
问题 I'm trying to use an alias in a shell script I'm writing, but it is not working. The alias: alias ts="awk '{ print strftime(\"[%Y-%m-%d %H:%M:%S]\"), \$0 }'" When I run the script, I get the following error: ./copyTask.sh: ts: not found Sooping around on the internet, it seems that I need to enable the expand_aliases shell option, but I don't have shopt installed... Is there any way I can enable alias expansion without using shopt or creating another rootfs image? I'm using the ash shell. And

Equivalent of exec 3<>/dev/tcp/anyaddress.com/80 in ash

孤者浪人 提交于 2021-02-04 19:40:07
问题 In bash the following command open a socket exec 3<>/dev/tcp/192.168.1.200/8080 In the ash this command does not work. Are there an equivalent of this command for ash? here after the output error of the command in ash: -ash: can't create /dev/tcp/192.168.1.200/8080: nonexistent directory 回答1: No, there is not. The standard POSIX bourne shell doesn't offer this feature. You may be able to accomplish what you need with socat or nc. This bash feature is very strange by the way, considering that

follow logfile with tail and exec on event

五迷三道 提交于 2021-01-29 05:01:38
问题 i wonder if there is a more simplyfied way to run the tail -f or -F on a logfile and execute a command each time a special keyword is mentioned. this is my working solution so far, but i don't like it for following reasons: i have to write new lines for each match to log file to avoid endless loop tail does not follow exactly the log, it could miss some lines while the command is executed i am not aware about CPU usage because of high frequency example: #!/sbin/sh while [ 1 ] do tail -n1

All newlines are removed when saving cat output into a variable

青春壹個敷衍的年華 提交于 2020-12-29 02:44:43
问题 I have the following file linux$ cat test.txt toto titi tete tata Saving the cat output into a variable will discard the newlines linux$ msgs=`cat test.txt` linux$ echo $msgs toto titi tete tata How to keep the output containing the newlines in the variables? 回答1: The shell is splitting the msgs variable so echo get multiple parameters. You need to quote your variable to prevent this to happen: echo "$msgs" 回答2: I had this: echo $(cat myfile.sh) >> destination.sh that was causing the problem,

All newlines are removed when saving cat output into a variable

左心房为你撑大大i 提交于 2020-12-29 02:43:09
问题 I have the following file linux$ cat test.txt toto titi tete tata Saving the cat output into a variable will discard the newlines linux$ msgs=`cat test.txt` linux$ echo $msgs toto titi tete tata How to keep the output containing the newlines in the variables? 回答1: The shell is splitting the msgs variable so echo get multiple parameters. You need to quote your variable to prevent this to happen: echo "$msgs" 回答2: I had this: echo $(cat myfile.sh) >> destination.sh that was causing the problem,

How to keep program running in background in ash shell

≡放荡痞女 提交于 2020-06-15 23:42:22
问题 I need to SSH to an embedded device, launch a background program, then disconnect and keep the background process running. The problem is that the embedded device is using the ash shell (NOT bash or anything else), so nohup and screen are NOT available. I have not been able to find any way of disconnecting the process in ash. Is there any way of doing this in ash? 回答1: An alternative to: nohup command & Using clever parentheses: (( command & ) & ) And also if you want to drop stdin/stdout: ((

How to keep program running in background in ash shell

假装没事ソ 提交于 2020-06-15 23:42:15
问题 I need to SSH to an embedded device, launch a background program, then disconnect and keep the background process running. The problem is that the embedded device is using the ash shell (NOT bash or anything else), so nohup and screen are NOT available. I have not been able to find any way of disconnecting the process in ash. Is there any way of doing this in ash? 回答1: An alternative to: nohup command & Using clever parentheses: (( command & ) & ) And also if you want to drop stdin/stdout: ((

How to keep program running in background in ash shell

陌路散爱 提交于 2020-06-15 23:42:10
问题 I need to SSH to an embedded device, launch a background program, then disconnect and keep the background process running. The problem is that the embedded device is using the ash shell (NOT bash or anything else), so nohup and screen are NOT available. I have not been able to find any way of disconnecting the process in ash. Is there any way of doing this in ash? 回答1: An alternative to: nohup command & Using clever parentheses: (( command & ) & ) And also if you want to drop stdin/stdout: ((

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