bash

How to store command arguments which contain double quotes in an array?

不羁岁月 提交于 2021-02-10 06:45:50
问题 I have a Bash script which generates, stores and modifies values in an array. These values are later used as arguments for a command. For a MCVE I thought of an arbitrary command bash -c 'echo 0="$0" ; echo 1="$1"' which explains my problem. I will call my command with two arguments -option1=withoutspace and -option2="with space" . So it would look like this > bash -c 'echo 0="$0" ; echo 1="$1"' -option1=withoutspace -option2="with space" if the call to the command would be typed directly

awk command to create sha2 of individual column and paste into new file

烈酒焚心 提交于 2021-02-10 06:24:07
问题 I have a file of having multiple rows. Using that original file I am creating one more files but in that new file i am taking only few columns of the original files. What I have to do is, instead of just picking few columns and pasting in new files, I need to create sha2 of first column and paste in new file as plain value also as well as sha2 value. Hope I am clear. This is the awk command I am using to do the same. awk -F '|' -v OFS='|' -v var="10|" '(NR - 1) != 0 {$2=var$2; print $2,$3,$4,

Emacs and. sh (or. bash)?

﹥>﹥吖頭↗ 提交于 2021-02-10 06:19:32
问题 I've tried finding an Emacs specific answer to this one, so apologies if it is repetitive. Simple question. I know that from the point of view of the interpreter it doesn't matter if you write a bash script with or without the .sh or. bash suffix, but does using one of either of these change the way in which Emacs treats the file when editing it? I've been playing around with some bash scripts in Emacs, and I've half answered my question. But I'm brand new to bash, so a lot is still unclear.

User Idle time in Linux

我们两清 提交于 2021-02-10 06:19:11
问题 I need to check how much time passed since last user input occurence (preffered way - in python) on Linux (lucid - 10.4) I know that this is easy in normal way (just using XScreenSaverQueryInfo), but the tricky part is that I don't have x11/extensions/scrnsaver.h header and I HAVE to do that some other way (even if I install needed package I cannot install packeges on 100 other computers on which it will work - I don't have permission to do that). 回答1: In deps of internet I found something

Error: must use subscript when assigning associative array

﹥>﹥吖頭↗ 提交于 2021-02-10 06:18:32
问题 I wanted a hashmap equivalent in bash (keys as string and values as a list of integers). So, I wrote the following code- declare -A PUBS PUBS=( "FEE":"[345, 342]" "FOO":"[1, 2, 44]" "BAR":"[23, 67]" ) However, I get an error saying must use subscript when assigning associative array . What's wrong here? 回答1: You're not using the correct syntax to specify the keys. It's [key]=value , not key:value . So it should be: PUBS=( ["FEE"]="[345, 342]" ["FOO"]="[1, 2, 44]" ["BAR"]="[23, 67]" ) 来源:

Error: must use subscript when assigning associative array

旧巷老猫 提交于 2021-02-10 06:18:10
问题 I wanted a hashmap equivalent in bash (keys as string and values as a list of integers). So, I wrote the following code- declare -A PUBS PUBS=( "FEE":"[345, 342]" "FOO":"[1, 2, 44]" "BAR":"[23, 67]" ) However, I get an error saying must use subscript when assigning associative array . What's wrong here? 回答1: You're not using the correct syntax to specify the keys. It's [key]=value , not key:value . So it should be: PUBS=( ["FEE"]="[345, 342]" ["FOO"]="[1, 2, 44]" ["BAR"]="[23, 67]" ) 来源:

Optimising my script which lookups into a big compressed file

六月ゝ 毕业季﹏ 提交于 2021-02-10 05:56:29
问题 I'm here again ! I would like to optimise my bash script in order to lower the time spent for each loop. Basically what it does is : getting an info from a tsv using that information to lookup with awk into a file printing the line and exporting it My issues are : 1) the files are 60GB compressed files : I need a software to uncompress it (I'm actually trying now to uncompress it, not sure I'll have enough space) 2) It is long to look into it anyway My ideas to improve it : 0) as said, if

Change directory using loop in linux

你说的曾经没有我的故事 提交于 2021-02-10 05:42:06
问题 I want to change directory to perform a task in each directory. Following is the code: for i in {1..10} do cd dir/subdir$i bla... bla.. bla.. done However I am getting error: not found [No such file or directory] I have tried the following but still getting the same above error: cd $(echo dir/subdir"$i") cd $(eval dir/subdir"$i") 回答1: The problem is probably because all the directories you want to change into are relative from the original base directory. One way to solve this is using a (...

Change directory using loop in linux

喜欢而已 提交于 2021-02-10 05:41:15
问题 I want to change directory to perform a task in each directory. Following is the code: for i in {1..10} do cd dir/subdir$i bla... bla.. bla.. done However I am getting error: not found [No such file or directory] I have tried the following but still getting the same above error: cd $(echo dir/subdir"$i") cd $(eval dir/subdir"$i") 回答1: The problem is probably because all the directories you want to change into are relative from the original base directory. One way to solve this is using a (...

Change directory using loop in linux

为君一笑 提交于 2021-02-10 05:41:06
问题 I want to change directory to perform a task in each directory. Following is the code: for i in {1..10} do cd dir/subdir$i bla... bla.. bla.. done However I am getting error: not found [No such file or directory] I have tried the following but still getting the same above error: cd $(echo dir/subdir"$i") cd $(eval dir/subdir"$i") 回答1: The problem is probably because all the directories you want to change into are relative from the original base directory. One way to solve this is using a (...