unix

Change variable named in argument to bash function [duplicate]

女生的网名这么多〃 提交于 2021-02-10 18:48:43
问题 This question already has answers here : Dynamic variable names in Bash (16 answers) How to use a variable's value as another variable's name in bash [duplicate] (6 answers) Closed 3 years ago . In my bash scripts, I often prompt users for y/n answers. Since I often use this several times in a single script, I'd like to have a function that checks if the user input is some variant of Yes / No, and then cleans this answer to "y" or "n". Something like this: yesno(){ temp="" if [[ "$1" =~ ^([Yy

Evaluate expression inside bash for loop [duplicate]

非 Y 不嫁゛ 提交于 2021-02-10 15:16:19
问题 This question already has answers here : How do I iterate over a range of numbers defined by variables in Bash? (20 answers) Closed 5 years ago . If I do this, I get the result as expected. for i in {125..129}; do echo $i; done 125 126 127 128 129 But when I do this? I get something weired. for i in {$((1+(25-1)*500))..$((25*500))}; do echo $i; done {12001..12500} I wish to pass a variable inside the loop variables like $((1+($j-1)*500)) 回答1: Bash's brace expansion has limitations. What you

Evaluate expression inside bash for loop [duplicate]

别来无恙 提交于 2021-02-10 15:14:16
问题 This question already has answers here : How do I iterate over a range of numbers defined by variables in Bash? (20 answers) Closed 5 years ago . If I do this, I get the result as expected. for i in {125..129}; do echo $i; done 125 126 127 128 129 But when I do this? I get something weired. for i in {$((1+(25-1)*500))..$((25*500))}; do echo $i; done {12001..12500} I wish to pass a variable inside the loop variables like $((1+($j-1)*500)) 回答1: Bash's brace expansion has limitations. What you

Capturing stdout/stderr separately and simultaneously from child process results in wrong total order (libc/unix)

天涯浪子 提交于 2021-02-10 14:43:49
问题 I'm writing a library that should execute a program in a child process, capture the output, and make the output available in a line by line (string vector) way. There is one vector for STDOUT, one for STDERR, and one for "STDCOMBINED", i.e. all output in the order it was printed by the program. The child process is connected via two pipes to a parent process. One pipe for STDOUT and one for STDERR. In the parent process I read from the read-ends of the pipes, in the child process I dup2() 'ed

Capturing stdout/stderr separately and simultaneously from child process results in wrong total order (libc/unix)

倖福魔咒の 提交于 2021-02-10 14:42:20
问题 I'm writing a library that should execute a program in a child process, capture the output, and make the output available in a line by line (string vector) way. There is one vector for STDOUT, one for STDERR, and one for "STDCOMBINED", i.e. all output in the order it was printed by the program. The child process is connected via two pipes to a parent process. One pipe for STDOUT and one for STDERR. In the parent process I read from the read-ends of the pipes, in the child process I dup2() 'ed

MAC OS X alias folder/file do not persist on Windows

让人想犯罪 __ 提交于 2021-02-10 13:15:48
问题 I have one Folder and I have created an Alias (Short-cut) on my MAC OS Desktop. Now, when I copy that Alias from MAC OS to Windows, then it shows me a type of file as "File". Now if I again copy that Alias from Windows to Mac OS, then that alias is now Unix Executable file and Not an Alias. I have tried zipping that Alias, and still having the same issue. Is it possible to persist MAC Alias on Windows and when i copy that Alias back to Mac then it remains Alias. 回答1: Mac filesystems can

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

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 (...