I’m new to bash scripting and trying to write the following simple And this works as expected. But if I delete echo “some string’ it prints nothing: Why? Why does deleting echo some_string right after the condition checking breaks the function? Answer It is because the if-condition is executed as a compound statement in bash i.e. command1;command2 and also incorrect
Tag: scripting
Capture output from external command and write it to a file
I am trying to create a script that calls on a linux command from my Ubuntu server and prints the output of aforementioned command to txt files. This is literally the first script I’ve ever written, I just started learning python recently. I want 3 files in 3 separate folders with filenames unique to date. It is failing at the
Export value of corresponding site out to a new text file
I have a text file that contains two columns of data, the first column being a site ID and the second being a value. If the value is equal to 0, I want to send the corresponding site ID out to a new file. If the value is equal to 15, I want to do nothing. Text File: Attempted Script:
Bash script to copy the directory structure from source directory into target directory
I am very new to Bash scritping and to get some practice, I am attempting to write a script that takes in a source directory and a destination directory. The script will search the source directory and copy its structure of sub-directories into the target directory (any files will be ignored, just the directories themselves will be duplicated). The source
How do I search for a certain piece of text inside of a variable?
I am working on a script which prompts the user for their username. Once entered, the script uses the ‘rwho’ command to get a list of users who are logged into the network. It should crosscheck the text they entered (their username) with the results from the rwho command. If a match is found then it displays a message saying
Combining videos with ffmpeg using crossfades and plain cuts
I am writing a script to combine/slice arbitrary video files from S3 into one output video. So far, I am doing this by first trimming the videos to their proper length using ffmpeg -i input-X.mp4 -ss start -t duration slice-X.mp4 and recombining the resultant slices with the ffmpeg concat filter. I want to be able to crossfade and cut between
How to put an executable script on the background and wake it up after x minutes
I’m developing a timer in bash and this is what I’ve come up with so far: It works like I was expecting except that I have to wait the X minutes I passed as input to get the prompt back. Any ideas how I can execute this and have it execute it in the background so I can keep working
Shell script doesn’t work when I export a variable inside it
I have a script called installscript which needs a change to the PATH variable. BuildScript file has the following code: Running ./BuildScript or source BuildScript fails with an error in installscript I have made a NewScript and call BuildScript from it after exporting the PATH variable running source NewScript works. I don’t understand why running BuildScript alone won’t work. Answer
How to echo a dynamic variable’s content in shell script
How to echo a dynamic variable’s content in shell script ? Current output: Desired output: Answer Use eval:
Obtaining UNIQUE VALUE occurrences count in a set of COLUMNS using AWK
IGNORING columns 1 & 2 (only the rest of the columns); I would like to obtain the occurrence COUNT of UNIQUE EVEN values (ignoring ODD ones) for the following set of data. I have tried: I obtain 76 but I don’t expect this value. Answer You can try this awk command to count unique values ignoring 1st and 2nd column: