New answers tagged

0

Serge's comment made me do my homework - study the man page in more depth than before. The solution was simply to enter in the shell losetup (without any arguments). Then, afterwards, losetup -f resulted, successfully, in /dev/loop0


3

You can not modify the variable inside the for cycle like this in bash. Oh ... you can, but it will not affect the iterations. It is not counted loop as we can be used to from C. Minimal example: #!/bin/bash for i in {1..3} do echo $i i=$((i-1)) echo $i done obviously prints: ./b.sh 1 0 2 1 3 2 You would better be with standard loop with ...


2

A simple change from for value in $name to for value in ${!name} will make your script work correctly: array1="name1 name2"; name1="one two"; name2="red blue" for name in $array1 ; do for value in ${!name} ; do printf '%s - %s\n' "$name" "$value" done done However, it should be pointed that the variable called array1 is ...


0

Using GNU Parallel it looks like this: seq 100 | parallel -j0 mount device{} dir{} If you have a list of dirs: parallel -j0 mount device{#} {} ::: dirs* If you have a list of devices: parallel -j0 'mkdir -p dir{#}; mount {} dir{#}' ::: device* GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on ...


1

As St├ęphane Chazelas points out, a list of words is not the same an array. However, you can use indirect expansion like this: array1="name1 name2" name1="one two" name2="red blue" for name in ${array1} do for value in ${!name} do echo "$name - $value" done done In this case, ${!name} introduces a level of indirection.


5

That's not how you define arrays in bash. a="foo bar" defines a string/scalar variable. And using it as $a (unquoted) performs the split+glob operator which only makes sense for strings representing a $IFS separated list of file patterns. In bash, arrays are defined as: a=(foo bar) So here, you'd want: array1=(name1 name2) name1=(one two) name2=(red ...



Top 50 recent answers are included