for

Output of loop variable shows different value than expected

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 "$(dir)" done I was expecting an output like: …

Total answers: 1

How to run for loop over SSH on remote so that variables expand?

How to run for loop over SSH on remote so that variables expand? If I ls files without a for loop in a remote host everything is fine however, if I capture the ls in a variable and try to echo each file it fails as the variables don’t expand/have a value. What I mean: …

Total answers: 2

"for i in" loop with multiple vars

"for i in" loop with multiple vars I have two variables VAR1="1 2 3" VAR2="Bob Tom Kate" I want to echo something like this but I don’t know how to use multiple variables in a loop: 1 for Bob 2 for Tom 3 for Kate All I can is: ( for i in $VAR1; do …

Total answers: 3

Unix. Run script across multiple dirs on specific files, where pathname has regex

Unix. Run script across multiple dirs on specific files, where pathname has regex I want to make a bash script (split.sh) that iterates across multiple dirs with same suffix, and then runs a function for specific files within them. I am almost there: #!/bin/bash path="/mypath/MAP-9-[0-9][0-9][0-9]" for filename in $path/*bam; do [ -e "$filename" ] || …

Total answers: 2

Why does the test command apparently choke on a for loop variable?

Why does the test command apparently choke on a for loop variable? I want to determine all broken symlinks within a directory. In ignorance of a better solution, I tried this simple bash one-liner (bash version is 4.2.46, which may be worth mentioning because it’s a bit dated): for f in $(ls); do test -L …

Total answers: 1

looping through directories in bash skipping a particular directory name

looping through directories in bash skipping a particular directory name I am trying to loop through directories within a given folder and I want to skip a particular directory name. I have written this bash script to do it, but this is giving me errors. Please tell me where I am going wrong: for f …

Total answers: 1

Awk commands for each arg

Awk commands for each arg I have an awk implementation in a bash script which I want to run for each function arg using a do loop. Each arg is composed of a multiline string. for arg in "$@"; do done Here is the awk implementation which uses <<< "$@" to pass all function arguments. …

Total answers: 1

Errors appending text with `sed`

Errors appending text with `sed` I have a podman-compose file: version: "3.8" services: kiwix-serve: image: docker.io/kiwix/kiwix-serve:3.3.0-1 volumes: – kiwix_data:/data – /home/meijin3/zim/gutenberg_en_all_2022-10.zim:/data/gutenberg_en_all_2022-10.zim – /home/meijin3/zim/wikipedia_en_all_mini_2022-09.zim:/data/wikipedia_en_all_mini_2022-09.zim ports: – 8080:80 command: /data/wikipedia_en_all_mini_2022-09.zim /data/gutenberg_en_all_2022-10.zim I’m attempting to create a script that will search for all .zim files in /home/meijin3/zim/. It will replace any existing lines in my compose file that …

Total answers: 1

Using variables inside the for loop in shell

Using variables inside the for loop in shell 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}" =~ ^[A-Za-z]*$ ]]; then echo "$i variable is a word" else echo "$i variable is not a word" fi done …

Total answers: 2

Looping over dirs using `find . -depth 1 -type d`

Looping over dirs using `find . -depth 1 -type d` I’ve been given a script to run, but it produces an error when calling find . -depth 1 -type d. It produces the following error, find: paths must precede expression: `1′ This is the line in which it fails, for dir in `find . -depth …

Total answers: 3

How to rename numerically titled file names by 1 digit?

How to rename numerically titled file names by 1 digit? This feels so simple, and yet I’m entirely stumped. Needless to say I am absolutely new to this. I have a directory with files numerically numbered from 000 to 020. I would like to rename these files by adding 1 so that 000 becomes 001 …

Total answers: 2

Need to capture exit code of pylint command using find in Github actions

Need to capture exit code of pylint command using find in Github actions I am trying to implement a python linter using pylint. But I am getting the score of each python file and also displaying the suggestion to improve the score but I am also looking to terminate the GitHub action job if my …

Total answers: 1

Create directory using filenames and move the files to its respective folder

Create directory using filenames and move the files to its respective folder My question is a bit different than: Create directory using filenames and move the files to its repective folder Since in the same folder I have two similar copy of each file like: 001.txt and 001(1).txt ….. 100.txt and 100(1).txt For each two …

Total answers: 1

How to make a for loop to read directory names with spaces in them?

How to make a for loop to read directory names with spaces in them? I need to create a script to scan folders in a directory and take the name of each folder, make a .txt file, name it with the name of the folder and put inside that folder. For example: A directory that …

Total answers: 2