shell

what is the Java equivalent of Pythons's subprocess shell=True property?

大憨熊 提交于 2021-02-16 15:02:21
问题 I've been using python for a long time. python's system and subprocess methods can take shell=True attibute to spawn an intermediate process setting up env vars. before the command runs. I've be using Java back and forth and using Runtime.exec() to execute shell command. Runtime rt = Runtime.getRuntime(); Process process; String line; try { process = rt.exec(command); process.waitFor(); int exitStatus = process.exitValue(); } I find difficulty to run some commands in java with success like

How do I split a text file into an array by blank lines?

眉间皱痕 提交于 2021-02-16 14:19:28
问题 I have a bash command that outputs text in the following format: Header 1 - Point 1 - Point 2 Header 2 - Point 1 - Point 2 Header 3 -Point 1 - Point 2 ... I want to parse this text into an array, separating on the empty line so that array[0] for example contains: Header 1 - Point 1 - Point 2 And then I want to edit some of the data in the array if it satisfies certain conditions. I was looking at something like this Separate by blank lines in bash but I'm completely new to bash so I don't

Bash semicolon being equal to newline is not exactly true?

强颜欢笑 提交于 2021-02-16 14:12:25
问题 I've read in multiple articles that semicolon( ; ) in UNIX-like shells is equal to a new line. However, the following is confusing me and I'm having no luck googling it either. I'm guessing it's an issue with do in shell, but "bash semicolon do" is not exactly the most google-friendly search term combination. Below is a simple for statement. for i in {1..10} do echo "hi" echo "bye" done As many Stack Overflow gurus have posted, every newline can be substituted with semicolons. So.. we have

Sed Insert Multiple Lines

ぐ巨炮叔叔 提交于 2021-02-16 10:23:15
问题 I'm trying to do an insert with sed (having just read up on it) and i'm being stumped by trying to insert multiple lines? What i'm currently doing is: sed -i "${line} i\ /* Name - ID */ \ select @ID = NULL \ from Animals \ where VrsnID = @VrsnID \ and Request= \"Request\" \ \ " animalNames.txt Note echo $line == 131 New Problem Everything appears on one line in the output? (also missing the first indent) /* Name - ID */ select @ID = NULL from Animals where VrsnID = @VrsnID and Request=

Sed Insert Multiple Lines

自闭症网瘾萝莉.ら 提交于 2021-02-16 10:22:32
问题 I'm trying to do an insert with sed (having just read up on it) and i'm being stumped by trying to insert multiple lines? What i'm currently doing is: sed -i "${line} i\ /* Name - ID */ \ select @ID = NULL \ from Animals \ where VrsnID = @VrsnID \ and Request= \"Request\" \ \ " animalNames.txt Note echo $line == 131 New Problem Everything appears on one line in the output? (also missing the first indent) /* Name - ID */ select @ID = NULL from Animals where VrsnID = @VrsnID and Request=

Access bash positional parameter through variable

断了今生、忘了曾经 提交于 2021-02-16 09:17:25
问题 How to access bash positional parameter through a variable? e.g. I have a variable "pos", which can be anything between 1 to 6 (say). If pos==1 , I want to do: echo $1 If pos==2 , I want to do: echo $2 So on. Intuitively, I want to do something like: echo $$pos . I want to do it in one line. 回答1: Use variable indirection: echo "${!pos}" 回答2: Here are several solutions. Some may need a recent version of bash , others may still work with a very old one. Let us set up first our environment... $

Assigning output of a command to a variable(BASH)

风格不统一 提交于 2021-02-16 05:02:31
问题 I need to assign the output of a command to a variable. The command I tried is: grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}' I try this code to assign a variable: UUID=$(grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}') However, it gives a syntax error. In addition I want it to work in a bash script. The error is: ./upload.sh: line 12: syntax error near unexpected token ENE=$( grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}

Assigning output of a command to a variable(BASH)

徘徊边缘 提交于 2021-02-16 04:59:51
问题 I need to assign the output of a command to a variable. The command I tried is: grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}' I try this code to assign a variable: UUID=$(grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}') However, it gives a syntax error. In addition I want it to work in a bash script. The error is: ./upload.sh: line 12: syntax error near unexpected token ENE=$( grep UUID fstab | awk '/ext4/ {print $1}' | awk '{print substr($0,6)}

bash removing part of a file name

和自甴很熟 提交于 2021-02-15 11:01:24
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled

bash removing part of a file name

眉间皱痕 提交于 2021-02-15 11:01:11
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled