shell

What's the equivalent to ${var:-defaultvalue} in fish?

天涯浪子 提交于 2021-01-29 17:26:05
问题 Hello I am trying to translate my .bashrc to fish format almost done, mostly is clear on the documentation but this part is giving me a headache.. is so my gnupg works with my yubikey ssh etc etc.. The fish version is latest 3.0 under Arch GNU/Linux original on BASH: # Set SSH to use gpg-agent unset SSH_AGENT_PID if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh" fi echo "UPDATESTARTUPTTY" | gpg-connect-agent > /dev/null 2&>1 Mine

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

↘锁芯ラ 提交于 2021-01-29 17:14:38
问题 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 to create dictionary using shell script

余生颓废 提交于 2021-01-29 16:21:43
问题 I have a file status.txt which is in the following format: 1|A|B 2|C|D Now i have to read this file in shell script and create a dictionary like: dictionary['1'] = ['A', 'B'] dictionary['2'] = ['C', 'D'] I am able read the content of file using this: while read line do key=$line | cut --d="|" -f1 data1=$line | cut --d="|" -f2 data2=$line | cut --d="|" -f3 done < "status.txt" Can anybody help me in creating the dictionary as mentioned above. 回答1: According your idea with while loop, here is

Copy the second line of a csv in one directory to a csv in another directory

青春壹個敷衍的年華 提交于 2021-01-29 16:11:35
问题 File.csv is in directory: /a/b/c/File.csv I want to copy the second line of File.csv in output.csv which has to be created in directory /a So the final output is: /a/output.csv I tried to run in directory /a the command: sed -n '2p' /a/b/c/File.csv>output.csv But it didn't work. I also tried to run in directory /a/b/c the command: sed -n '2p' File.csv>/a/output.csv But it dind't work What am I doing wrong? 回答1: The line number goes outside of the '' as in: sed -n 2'p' sourcefile.csv >

bash script infinite loop one line syntax

自作多情 提交于 2021-01-29 15:16:19
问题 I have a simple bash script which reads from a file, line by line and prints it to the screen (adopted from another SO answer). while IFS= read -r line || [[ -n "$line" ]]; do echo "$line"; sleep 2; done < testfile.txt I want to make this an infinite loop so that once it reaches the end of the file, it starts from the beginning again: I tried adding a while true; / while [ 1 ]; / even a while :; at the beginning, but none of these work. Upon pressing enter, it gives the > prompt. How do I

How to match the syntax in file if matches display success or fail

我与影子孤独终老i 提交于 2021-01-29 15:14:30
问题 I have a scenario where i have following below data in Student file My Student.txt data input, need to follow a pattern, on each line need to contains three infos separated by / as follows: NAME/SURNAME/COUNTRY So, below I have an example of file that is fine: RAM/ABC/INDIA RAJ/XYZ/DELHI VIRAJ/FDS/GUJRAT WHAT IS EXPECTED: Each and every record in file should match with that syntax: NAME/SURNAME/COUNTRY . If anyone fails then, the overall status should be displayed as failed, with the message

Shell script - find: missing argument to `-exec'

女生的网名这么多〃 提交于 2021-01-29 15:00:18
问题 I'm trying to run this script: alias logs="cd L:/" find $logs -name '*system.log*' -mtime +14 -exec rm {} \; But get this error: find: missing argument to `-exec'. I've tried looking at other posts on this but can't get it working. I'm using cygwin to run this script on Windows. 回答1: If you have created any alias with name log , then to use it, you should be using $logs and not logs Also, maybe the find you are using is of Windows and not of Cygwin . This is made clear if you type 'which find

Multiple Read statements. Do not proceed until user input is given

陌路散爱 提交于 2021-01-29 14:43:37
问题 I have a few read statements. Im trying to figure out how to prevent the user from going to the next statement unless they have provided user input. I am having trouble wrapping my head around this. I have seen examples for a single read -p statement but can't seem to find an appropriate solution for multiple subsequent read statements. read -p " Write something: " var1 read -p " Write something again: " var2 read -p " write something a third time: " var3 desired output Write something: #no

Write information from a lookup file into another file

落爺英雄遲暮 提交于 2021-01-29 14:25:18
问题 There is a directory of files that have the following content: doc1.tsv <http://uri.gbv.de/terminology/bk/86.56> <http://uri.gbv.de/terminology/bk/58.28> doc2.tsv <http://uri.gbv.de/terminology/bk/44.43> <http://uri.gbv.de/terminology/bk/58.28> <http://uri.gbv.de/terminology/bk/44.38> Also, there is a lookup file vocab.tsv which contains class names with respect to the numeric coding: <http://uri.gbv.de/terminology/bk/44.38> Pharmakologie <http://uri.gbv.de/terminology/bk/44.43> Medizinische

Extract the unpredictable data that have its own timestamp in a log file using a Shell script

一笑奈何 提交于 2021-01-29 14:16:42
问题 log.txt will be as below, which are the ID data with its own timestamp (detection_time) that will continuously update in this log.txt file. The ID data will be unpredictable number. It could be from 0000-9999 and the same ID could be appeared in the log.txt again. My goal is to filter the ID that appears again in the log.txt within 15 sec from its first appearance by using shell script. Can anyone help me with this? ID = 4231 detection_time = 1595556730 ID = 3661 detection_time = 1595556731