I have a requirement to change the contents of config.tsx file that contains values like: I want to change this content using a shell script and save the file. Changed content can look like: How can I do this? Answer This should work: The -i option will edit the file in place. If you first want to try the com…
Tag: bash
Can substring expansion be used in dash shell or bourne shell?
I’m converting an app to a new image, and the existing commands use substring expansion to set the artifact version like so: mvn clean versions:set -DnewVersion=”0.1.$VCSINFO.I${INFO:0:6}.M$OTHER_INFO”. I’m using a ubuntu image that defaults to /bin/sh, and I am unable to figure out ho…
shell if statment executing even if its not true [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 y…
Bash terminal error when using ‘unmask’ command [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 y…
How to read a variable from file, modify and safe it to an other variale
What I want: There is a file /scripts/backup/config.cfg which contains variables. In my specific case the important ones are: Then there is a script /scripts/backup/performBackup.sh For a specific reason I want a part of the script do the following operations: read the value of the variable ROOTLOCATION add a…
Create python script to run terminal command with source
Long story short, I’m trying to figure out a way to turn these command lines into a script or function in python that can be called by another python application. These are the command lines in Linux: At first I was like this will be easy its just launching the application in python – but I’…
Recursively replace linux file and folder names such as “%m-%d-%y.tar” with their actual creation month/day/year
I’m looking for something like this but with its original creation date instead of the current date. Example: This folder (output below is from Linux command ls -ltr) would have its file name changed to “04-26-20”. Answer Since there are some information missing I try to make assumptions and…
Bash: process all files in a directory
How would I apply a logic to all files in a directory and pipe the final output of each input file to a separate file? Something like below (actual command is long, but I used above for simplicity to better understand the logic to all the files in a directory) Answer You can use a for-loop over the filenames:…
Declaring variables with indirect reference with a prefix
I have my parameters stored in a file and calling them with a prefix which i get it has input. now, i am getting the input and prefixing it and storing as a new variable and then pointing my new variable indirectly to my actual variable to use in my script. Is there a way to directly mention the indirect
Bash: syntax error operand expected “=”, in assignment statement in a for loop
EDIT: I think that it’s not picking up the $1 as the operand. I tried storing it in a variable, then trying the assignment but it seems that has no effect. EDIT 2: provided a minimal reproducible script as requested. The error generating part of the code is the following: the rest of the function’…