Reading all files inside a folder with bash [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
The problem is to read all files inside a folder and apply certain functions specified in the bash script over each file. Somewhat like calling map() in an object in JavaScript, but in this case with bash.

you just need to loop over the files. Assume your pwd is that folder:
for file in *.txt; do
do your stuff here with "$file" ...
done

Related

Bash - How to share constants between scripts? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to make it so that there isn't a list of constants at the top of every bash script i have? I have a lot of readonly constants for formatting and such but having them at the top of every single one of my scripts takes up space. Is there a way to make a separate script containing all of them and access it or something? or some way to clean it up?
Use a common script that you source in your other scripts.
E.g. source common.sh will execute that file and you may export variables there.
This is also how files like .bashrc and .bash_profile work, it is sourced when you execute bash (the latter when it is a login shell). When you change .bashrc, you can source it again in the running shell for the changes to take effect.

Meaning of 2 in's in shell script for loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What does the 2nd "in" do? I can't seem to find this kind of example anywhere other than this one right here.
for a in in /home/davidwright/attachments/*/*.tar
do
echo "extracting $x"
tar -xvf $x
done
Looks like a typo. It means the loop iterates with the string "in" as the first value assigned to a, then proceeds to iterate over the results of the glob. The shell's just not that picky, and every item after the first in is a thing to iterate over in the for loop. Unless there is a file named in that is known to exist, tar will complain when it tries to unpack the non-existent in file.

replace strings with shell variables in text file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm writing a shell script in which I've created some variables.
RELEASE="something"
COMMONS="something else"
I've got a file file.txt in which there are some occurrences of $RELEASE and $COMMONS. I want to replace these strings with the corresponding shell variable. I've tried to run (and a lot of other variations):
sed "s|\$RELEASE|${RELEASE}|g" file.txt > result.txt
It replaces "$RELEASE" with "${RELEASE}." Have you any idea how to replace by the value of $RELEASE?
Try this :
sed 's|$RELEASE|'"$RELEASE"'|g' file.txt > result.txt

Bash script - Merging Pdfs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
hi i have a few thousand single paged pdf files in one folder and one single paged pdf(its file name is 2.pdf). I want to merge all the pdfs in the folder with the 2.pdf file. at the end should have all the pdfs in the folder with 2pages and the second page being the contents of 2.pdf. Please assist on this. thanks
So for all PDF files of the current directory, except 2.pdf, we merge x.pdf with 2.pdf as a new file called new-x.pdf. So we can use the command given in merge / convert multiple pdf files into one pdf to do this:
cover="2.pdf";
outputDir="output-pdfs/";
mkdir "$outputDir";
for f in *.pdf; do
[[ "$f" == "$cover" ]] && continue # skip the cover PDF
pdfunite "$f" "$cover" output-pdfs/new-"$f".pdf;
done

Identifying and adapting unix-"isms" to the Windows command prompt [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In the Python Pyramid tutorial, I encountered this phrase:
"Windows users will need to adapt the Unix-isms below to match their environment."
It appears to relate to the "Export" command, but I am not entirely sure. The question therefore, is how do others go about this process of identifying and adapting "Unix-isms"? My only method so far is to see what isn't recognized, and obviously that could be due to different reasons.
Regarding research, I may have found a paywalled explanation for export specifically, but I'm sure there are better resources for adapting these commands.
Thank you!
The $ symbol is a Unix prompt
The ; is a command separator
export sets sets an environment variable, similar to setx
PATH=/path/to/tutorial_workspace/venv/bin:$PATH is modifying the PATH environment variable, similar to PATH=/path/to/tutorial_workspace/venv/bin;%PATH%
which searches the PATH for a program and returns its location.

Resources