bash

How to generate a random decimal number from 0 to 3 with bash?

…衆ロ難τιáo~ 提交于 2021-02-05 08:12:18
问题 I want to generate a random decimal number from 0 to 3, the result should look like this: 0.2 1.5 2.9 The only command I know is: echo "0.$(( ($RANDOM%500) + 500))" but this always generates 0.xxx . How do I do that ? 回答1: Bash has no support for non-integers. The snippet you have just generates a random number between 500 and 999 and then prints it after "0." to make it look like a real number. There are lots of ways to do something similar in bash (generating the integer and decimal parts

How to generate a random decimal number from 0 to 3 with bash?

巧了我就是萌 提交于 2021-02-05 08:12:09
问题 I want to generate a random decimal number from 0 to 3, the result should look like this: 0.2 1.5 2.9 The only command I know is: echo "0.$(( ($RANDOM%500) + 500))" but this always generates 0.xxx . How do I do that ? 回答1: Bash has no support for non-integers. The snippet you have just generates a random number between 500 and 999 and then prints it after "0." to make it look like a real number. There are lots of ways to do something similar in bash (generating the integer and decimal parts

In Python subprocess, what is the difference between using Popen() and check_output()?

佐手、 提交于 2021-02-05 08:08:50
问题 Take the shell command "cat file.txt" as an example. With Popen, this could be run with import subprocess task = subprocess.Popen("cat file.txt", shell=True, stdout=subprocess.PIPE) data = task.stdout.read() With check_output, one could run import subprocess command=r"""cat file.log""" output=subprocess.check_output(command, shell=True) These appears to be equivalent. What is the difference with regards to how these two commands would be used? 回答1: Popen is the class that defines an object

In Python subprocess, what is the difference between using Popen() and check_output()?

≡放荡痞女 提交于 2021-02-05 08:08:48
问题 Take the shell command "cat file.txt" as an example. With Popen, this could be run with import subprocess task = subprocess.Popen("cat file.txt", shell=True, stdout=subprocess.PIPE) data = task.stdout.read() With check_output, one could run import subprocess command=r"""cat file.log""" output=subprocess.check_output(command, shell=True) These appears to be equivalent. What is the difference with regards to how these two commands would be used? 回答1: Popen is the class that defines an object

Mathematical expression result assigned to a Bash variable

陌路散爱 提交于 2021-02-05 07:57:45
问题 How do I save the result of evaluating a mathematical expression to a variable using bash? My code is the following: W1=$(bpimagelist -U -d 11/01/2013 00:00:00 -e 11/05/2013 00:00:00 -pt FlashBackup-Windows | tail -n +3 | awk '{s+=$5} END {print s/1024/1024/1024}') W2=$(bpimagelist -U -d 11/01/2013 00:00:00 -e 11/05/2013 00:00:00 -pt MS-Windows | tail -n +3 | awk '{s+=$5} END {print s/1024/1024/1024}') echo "$W1+$W2" | bc | awk '{printf "%.02f\n", $1}' Console Output: 96.86 I am looking for a

Run bash script in background by default

让人想犯罪 __ 提交于 2021-02-05 07:48:28
问题 I know I can run my bash script in the background by using bash script.sh & disown or alternatively, by using nohup . However, I want to run my script in the background by default, so when I run bash script.sh or after making it executable, by running ./script.sh it should run in the background by default. How can I achieve this? 回答1: Self-contained solution: #!/bin/sh # Re-spawn as a background process, if we haven't already. if [[ "$1" != "-n" ]]; then nohup "$0" -n & exit $? fi # Rest of

Ghostscript On windows leads to Invalid option for -dPDFSETTINGS

ぃ、小莉子 提交于 2021-02-05 07:45:08
问题 To solve my problem here with compressing/down-sizing a PDF file generated by MikTeX on Windows, I am trying this bash script on Cmder as: shrinkpdf.sh in.pdf > out.pdf However I get the error: Invalid value for option -dPDFSETTINGS=C:/Program Files/Git/screen, use -sNAME= to define string constants which I suppose has to do with the line -dPDFSETTINGS=/screen I would appreciate it if you could help me know what is the problem and how I can solve it. My environment is: Windows OS: 1809 Cmder:

Ghostscript On windows leads to Invalid option for -dPDFSETTINGS

断了今生、忘了曾经 提交于 2021-02-05 07:45:06
问题 To solve my problem here with compressing/down-sizing a PDF file generated by MikTeX on Windows, I am trying this bash script on Cmder as: shrinkpdf.sh in.pdf > out.pdf However I get the error: Invalid value for option -dPDFSETTINGS=C:/Program Files/Git/screen, use -sNAME= to define string constants which I suppose has to do with the line -dPDFSETTINGS=/screen I would appreciate it if you could help me know what is the problem and how I can solve it. My environment is: Windows OS: 1809 Cmder:

How to make a comparison between sentences and calculate the similarity?

馋奶兔 提交于 2021-02-05 07:36:17
问题 How to make a comparison between the first sentence of the second sentence and the first sentence with the third sentence and so on, and calculate the similarity using shell script or bash I have a sentences containing duplicate words, for example, the input data in file my_text.txt and should ignore duplicated words per sentence, filler words, and non-alphabetical characters. Shell Script Linux Shell Script Shell or bash are fun I used this shell script to find similarity words=$( < my_text

How to make a comparison between sentences and calculate the similarity?

佐手、 提交于 2021-02-05 07:36:01
问题 How to make a comparison between the first sentence of the second sentence and the first sentence with the third sentence and so on, and calculate the similarity using shell script or bash I have a sentences containing duplicate words, for example, the input data in file my_text.txt and should ignore duplicated words per sentence, filler words, and non-alphabetical characters. Shell Script Linux Shell Script Shell or bash are fun I used this shell script to find similarity words=$( < my_text