The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
1answer
19 views

accessing substrings from lines in a text file and storing them

I have a text file like this chr1:16840617-16840780 RNU1-1 (2 columns are tab separated) chr3:142139047-142139211 RNU1-100P ............ ............ I want to loop over the lines ...
1
vote
1answer
31 views

reset for loop counter

Simple question: if I have a for loop (zsh) over an unreliable list, by which I mean the list contains entries that can't be predicted beforehand, then can I reset the for loop counter? This ...
2
votes
1answer
170 views

Attach files for sending mail which are the result set of find command

By using find command I got multiple files. Now I want to add all these files as mail attachment. Please help me how to add these files as attachment in single mail. I want to implement this in ...
3
votes
1answer
160 views

Why does this command to copy files in a for loop work in bash but not in zsh?

I'm trying to copy a bunch of files with the same name, but in different subdirectories, to a single directory, changing the names to ones based on the paths to the original files. I use a for loop ...
3
votes
6answers
612 views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
4
votes
3answers
1k views

For loop in Unix : including files from sub directories [duplicate]

A simple for loop in Unix would be: for FILE in $BASE_WORK_DIR/*.pdf do echo $FILE done This will echo all .pdf files inside BASE_WORK_DIR directory. What if BASE_WORK_DIR contains sub ...
4
votes
4answers
232 views

Continue for loop by keyboard

I have user account on a linux machine which I do not know its exact IP address. But I know a range which it is ran on one of them. I want to check which server is my desired server. There are some ...
0
votes
1answer
123 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
3
votes
4answers
162 views

Bash: For loop with binary range keeping control value binary

Let's say I have two bash variables that contain binary values: a=0011 # decimal 3 b=1000 # decimal 8 Is there a way I can loop through all the possible values between $a and $b keeping it binary? ...
1
vote
1answer
38 views

for + array + args

I have problem with my for cycle, this is what I want: for arg do array[index]=(`find $arg -type l -maxdepth $depth -printf "%p\n" `) index++ done fi arg - positional arguments, only directories ...
1
vote
3answers
63 views

return the numeric value of a indexed variable rather than its name [duplicate]

The following piece of code illustrates my problem I'm afraid I oversimplified it way too much in the first round. #!/bin/bash dogLover=1 catLover=2 for ii in dog cat do ...
2
votes
2answers
335 views

Using for loop to brute-force a password

I just wanted to brute-force my old router but the for-loop was really amateur style. How to write a nice for-loop, if I only know the charaters included? Found already that page but it does not ...
0
votes
0answers
25 views

Multiple media convertions fail [duplicate]

I have some of my CDs ripped to FLAC. Now, I want to rip them again in mp3. Since FLAC is lossless, I decided to run ffmpeg on them instead of the hassle to find the CDs, rip them etc. But I cannot! ...
2
votes
3answers
366 views

Command substitution in for loop not working

I want to keep all files not ending with .bat I tried for f in $(ls | egrep -v .bat); do echo $f; done and for f in $(eval ls | egrep -v .bat); do echo $f; done But both approaches yield the ...
0
votes
6answers
3k views

bash variables in for loop range [duplicate]

I want to print list of numbers from 1 to 100 and I use a for loop like the following: number=100 for num in {1..$number} do echo $num done When I execute the command it only prints {1..100} and ...
5
votes
3answers
576 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
2
votes
2answers
168 views

Why won't the for loop execute on directory

In the following script, the first for loop executes as expected, but not the second. I do not get any error, it seems that the script just hangs. HOME=/root/mydir DIR=$HOME/var DIRWORK=$HOME/Local ...
3
votes
4answers
3k views

Piping output to text file within a for loop

I'm trying to do the following within a for loop: Find files that satisfy a condition Echo the name of the files to a log file. Gzip the file. I can get the script to find the files and echo their ...
3
votes
3answers
196 views

${!FOO} and zsh

${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name. zsh doesn’t support this feature. Is there a way to make this work the same ...
1
vote
1answer
1k views

Behavior of while loop and for loop in unix script

I am trying to read user and server details from file tempo.txt and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh.But I am not able ...
5
votes
4answers
620 views

Avoiding errors due to unexpanded asterisk

In bash I often use for-loops such as the following for file in *.type; do sommecommand "$file"; done; to perform an operation for all files matching *.type. If no file with this ending is ...
14
votes
2answers
2k views

In bash, is it possible to use an integer variable in the loop control of a for loop?

I have the following bash script: #!/bin/bash upperlim=10 for i in {0..10} do echo $i done for i in {0..$upperlim} do echo $i done The first for loop (without the variable upperlim in the loop ...
0
votes
3answers
620 views

for loop with multiline data

I need to create a script with a loop through a list of items. I want to insert a string in the script. I tried: for i in " a b c"; do echo "test "$i done But that only outputs one string: test ...
0
votes
3answers
88 views

Why the code in a for loop is executed only in the first directory in a bash shell?

Under a directory called a there are many subfolders where I want to do something. The same for all. I do the following but it applies only to the first subdirectory: for i in "a/*" do ...
5
votes
1answer
5k views

In a bash shell script, writing a for loop that iterates over string values

In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers. For example, I can write a bash shell script that prints the integers ...
7
votes
3answers
3k views

Multivariable For Loops

Is there a way to specify multiple variables (not just integers) in for loops in bash? I may have 2 files containing arbitrary text that i would need to work with. What i functionally need is ...
1
vote
1answer
129 views

What's the right way to reuse this one-liner?

I recently came up with the following one-liner: for f in *.mp3; do sha1sum $f | sed -r 's/[a-z]//g' | cut -c1-2 | awk '{ print ($1 >= 255) ? $1 - $1 + (1/3)*$1 : $1 }' | xargs -i id3v2 -T {} $f; ...
0
votes
3answers
2k views

Why does this incrementing for loop return a bad variable?

I'm trying to call this shell script from within the CLI of GRASS GIS: for (( day=5; day<367; day+5 )); do # commands that I've tested without a loop. done exit 0 returns Syntax error: Bad ...