I have a file: /mnt/d/main_folder/sub_folder1/ak33.R
.
The ak33.R
file is in all the sub folders :
/mnt/d/main_folder/sub_folder2/ak33.R
/mnt/d/main_folder/sub_folder3/ak33.R
/mnt/d/main_folder/sub_folder4/ak33.R
/mnt/d/main_folder/sub_folder5/ak33.R
I wanted to run this ak33.R file from all these sub folders, how do i run using linux bash script using a for loop?
is there a command to read all the sub folders name and run them in for loop ?
CodePudding user response:
Try the following:
for d in /mnt/d/main_folder/sub_folder*/; do
Rscript "$d"ak33.R
done
If the sub folder number is just one character, you can use the ?
meta-character.
for d in /mnt/d/main_folder/sub_folder?/; do
Rscript "$d"ak33.R
done
CodePudding user response:
I tried the following at my environment:
#!/bin/bash
if [[ ! -d /mnt/d/main_folder ]]
then
echo "/mnt/d/main_folder not found"
else
AK33FOUND=0
for AK33FILES in $(find /mnt/d/main_folder -type f -name ak33.R 2>/dev/null)
do
if [[ -f "$AK33FILES" ]]
then
AK33FOUND=1
if [[ -x "$AK33FILES" ]]
then
$AK33FILES
else
echo "$AK33FILES execute permission denied."
fi
fi
done
if [[ 0 -eq $AK33FOUND ]]
then
echo "No ak33.R files found at /mnt/d/main_folder"
fi
fi
I like your name Grand father and Grand mother.