Skip to main content

All Questions

Tagged with
0 votes
1 answer
58 views

using a variable which has content separated by spaces in shell in a for loop

I am trying to read a variable with spaces on prompt and trying to use in a for loop., For example: Enter the items to read separated by space... apple orange kiwi read items for i in "$...
sabarish tr's user avatar
-1 votes
1 answer
65 views

Output of loop variable shows different value than expected

Imagine I have two folders in my current working directory: back/ and front/. I am trying to enter inside each of them and do some stuff. From the simple script below: for dir in */ ; do echo &...
Rigel F. do C.'s user avatar
1 vote
2 answers
2k views

Is there a syntax for a "for" loop over words or lines in a variable, that will work unmofdified in both bourne shell and zsh?

I have a variable that contains a list of strings, one per line, to be looped over in a for...in...do...done command. I move regularly between bourne shell and zsh. As far as I can understand it, zsh ...
Stilez's user avatar
  • 1,291
2 votes
2 answers
603 views

For loop through a variable vector

I have a for loop and case statements. The for loop has quite a bit element list and the case statement will assign an 1D array or a vector. These values will be used in for loop after. I have the ...
BircanA's user avatar
  • 21
2 votes
3 answers
6k views

How to loop through all the files in a directory and print all the file names, like the command tree

How can I mimic the tree command and iterate through all the files and subdirectories of a directory and echo all the file names? I thought that a subdirectory within a directory is still counted as a ...
John Smith's user avatar
0 votes
0 answers
24 views

for loop with a list ... entities with spaces [duplicate]

As a intermediate step I want to produce one line per string in '' with below script #!/usr/bin/env/ bash TOMCAT_OFF=('16:00 19.01.2023' '16:00 21.02.2023' '16:00 15.02.2023') for i in ${TOMCAT_OFF[@...
vrms's user avatar
  • 253
0 votes
2 answers
136 views

Using variables inside the for loop in shell [duplicate]

I'd like to use variables inside the for loop in shell. My current code: VAA="1st_first" VAB="2nd_second" VAC="3rd_third" for i in VAA VAB VAC; do if [[ "${i}...
Feriman's user avatar
  • 1,059
2 votes
1 answer
1k views

GNU Parallel with -j -N still uses one CPU

How can I get reasonable parallelisation on multi-core nodes without saturating resources? As in many other similar questions, the question is really how to learn to tweak GNU Parallel to get ...
Nikos Alexandris's user avatar
7 votes
3 answers
872 views

How can I assign the output of a command to different variables in each loop iteration?

I have a script something like this: for chain in http https ssh do iptables -nvxL $chain | tail -1 | awk '{print $2}' done But what I actually want to do is capture the output of the iptables ...
Aditya K's user avatar
  • 2,240
0 votes
1 answer
1k views

For loop in bash to input a new file in directory

For context: I am running Prokka (as a novice bioinformatician with no Prokka and little Bash experience) and I have multiple FASTA files. I have been told I need to produce a Bash loop that will ...
notknowingyet's user avatar
1 vote
1 answer
1k views

How to make a script to rename images and videos with the date of modification?

I have a gallery folder with images and videos in it named in unwanted format. I want to make a script that scans through each file in that directory and when it finds an image or a video to rename it ...
user avatar
4 votes
2 answers
1k views

How to run a loop inside sh -c

I'm having trouble understanding what I need to escape when using sh -c. Let's say I want to run the for loop for i in {1..4}; do echo $i; done. By itself, this works fine. If I pass it to eval, I ...
Christopher's user avatar
0 votes
1 answer
1k views

Looping through variables which is an output of another command

Hello I am learning Scripting here. I am trying to write a simple script using the 'for' loop. I have hundreds of folders in a folder called user. if i run this command i get a list of folders that i ...
ranjit abraham's user avatar
1 vote
1 answer
361 views

Delete folders from a directory once it's sbatch`ed in a for loop?

I am running a command using sbatch for a tool on the server, that takes a lot of space. The command uses some directories (some files) from a main directory(tq_first) in a for loop. I was wondering ...
Echo94's user avatar
  • 13
1 vote
2 answers
2k views

Use parent directory base name for making a new directories in a for loop

I am attempting to use a for loop to move files (e.g. .txt) into a new directory, where the original directory name as part of the name, but add an extra "with-new-files" onto the name so I ...
Michelle's user avatar

15 30 50 per page
1
2 3 4 5
9