0

I'm trying to create a bash script that reads in subfolders within a folder and uses the subfolder as an input for a python program, but for some reason, it can't recognize some simple commands.

So just as a reference, the python program I have takes in two inputs: the subfolder it's taking in (folder must only have files in it) and an output file name.

#!/bin/bash

PATH=/foo/bar/*
for folder in $PATH; do
        echo  "${folder##*/}"
        (cat "${folder##*/}" output.txt) | python3 program.py
done

I've ran the program by itself in the command line and it has worked numerous times, but for some reason this doesn't.

This is the resulting output:

$ bash fileread.sh
> File1
> fileread.sh: line 6: cat: command not found
> fileread.sh: line 6: python3: command not found
> File2
> fileread.sh: line 6: cat: command not found
> fileread.sh: line 6: python3: command not found

Clearly, the echo command works, but somehow the other two stopped working

1 Answer 1

2

PATH is a reserved variable. By using it for your own purpose, bash can't find the commands anymore. Just use a different name.

Also, if you want to store a list, it makes IMO more sense to use an array:

p=(/foo/bar/*)
for folder in "${p[@]}"
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.