bash

Bash input without pausing the script?

天大地大妈咪最大 提交于 2021-02-09 05:14:45
问题 In Bash the only way to get a (user) input seems to be to use the read method, which pauses the rest of the script. Is there any way to receive a command line input (ending with the enter key) without pausing the script. From what I've seen there may be a way to do it with $1 ..? 回答1: read -t0 can be used to probe for input if your process is structured as a loop #!/bin/bash a='\|/-' spin() { sleep 0.3 a="${a:1}${a:0:1}" echo -n $'\e'7$'\r'"${a:1:1}"$'\e'8 } echo 'try these /|\- , dbpq , |)>)

Bash input without pausing the script?

吃可爱长大的小学妹 提交于 2021-02-09 05:14:32
问题 In Bash the only way to get a (user) input seems to be to use the read method, which pauses the rest of the script. Is there any way to receive a command line input (ending with the enter key) without pausing the script. From what I've seen there may be a way to do it with $1 ..? 回答1: read -t0 can be used to probe for input if your process is structured as a loop #!/bin/bash a='\|/-' spin() { sleep 0.3 a="${a:1}${a:0:1}" echo -n $'\e'7$'\r'"${a:1:1}"$'\e'8 } echo 'try these /|\- , dbpq , |)>)

Bash assignment statement expansion in POSIX vs. non-POSIX mode

依然范特西╮ 提交于 2021-02-09 02:27:41
问题 The GNU bash manual has the following passage while talking about shell parameters: The command builtin does not prevent builtins that take assignment statements as arguments from expanding them as assignment statements; when not in POSIX mode, assignment builtins lose their assignment statement expansion properties when preceded by command. I can't figure out what it's talking about, and I also can not manage to write a command that differs in behavior of assignment expressions between

Bash assignment statement expansion in POSIX vs. non-POSIX mode

耗尽温柔 提交于 2021-02-09 02:24:24
问题 The GNU bash manual has the following passage while talking about shell parameters: The command builtin does not prevent builtins that take assignment statements as arguments from expanding them as assignment statements; when not in POSIX mode, assignment builtins lose their assignment statement expansion properties when preceded by command. I can't figure out what it's talking about, and I also can not manage to write a command that differs in behavior of assignment expressions between

Convert Julian Timestamp to Regular Time in UNIX

此生再无相见时 提交于 2021-02-09 01:57:12
问题 I need to convert Julian timestamp to Regular timestamp in UNIX using Bash. On Tandem OS, conversion is pretty straightforward - Example: 212186319010244541 $OLSAPP SYSTST 1> #interprettimestamp 212186319010244541 #interprettimestamp 212186319010244541 expanded to: 2455860 2011 10 25 16 10 10 244 541 I wish to do the same on UNIX environment. The conversion will be a part of a parser script. So one-liners would be greatly appreciated. UPDATE : INTERPRETTIMESTAMP inbuilt function on Tandem

grep multiple patterns single file argument list too long

大憨熊 提交于 2021-02-08 23:41:13
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

grep multiple patterns single file argument list too long

浪尽此生 提交于 2021-02-08 23:40:47
问题 I am currently searching for multiple patterns in a file. The file is of 90GB in size, I am searching on a particular field(from position 6-17 in each line). I am trying to get all the lines that contain any of a particular list of numbers. The current syntax I am using is: grep '^.\{6\}0000000012345\|^.\{6\}0000000012543' somelargeFile.txt > outputFile.txt For small number of patterns this works. For a large number of patterns I get the "Argument list too long" error. One alternative I have

How to run mongorestore after mongod in docker

青春壹個敷衍的年華 提交于 2021-02-08 20:54:06
问题 I'm trying to set up a mongodb-server with docker, let it download a dump from the web and populate it with that info. My problem is that I can make it run and fill the database, but after it's done that, it just closes. This was how I went about solving my problem: sudo -u mongodb /usr/bin/mongod --config $conf $args & mongorestore dump The problem here is that I can't run mongorestore if mongod isn't running, but if I start mongod with mongod & , then the container will close down after

linux主机巡检脚本(内存,磁盘,cpu)

試著忘記壹切 提交于 2021-02-08 19:44:11
#!/bin/bash #author by acrossyao #date: 2021-02-08 #放假巡检脚本 echo "---------------------------------------「OS系统巡检信息」---------------------------------------" #OS_IP=`hostname -i | awk '{print $1}'` OS_IP="" IPLIST=`hostname -i` for elem in $IPLIST do regex="\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\b" ckStep2=`echo $elem | egrep $regex | wc -l` if [ $ckStep2 -eq 0 ] then aa=1 else OS_IP+=$elem", " fi done OS_HOSTNAME=`hostname` OS

Compress heredoc declaration to one line in bash?

允我心安 提交于 2021-02-08 17:11:46
问题 I have this which works to declare a JSON string in a bash script: local my_var="foobar" local json=`cat <<EOF {"quicklock":"${my_var}"} EOF` The above heredoc works, but I can't seem to format it any other way, it literally has to look exactly like that lol. Is there any way to get the command to be on one line, something like this: local json=`cat <<EOF{"quicklock":"${my_var}"}EOF` that would be so much nicer, but doesn't seem to take, obviously simply because that's not how EOF works I