Skip to content

Tag: bash

Storing only part of output into shell variable

hi i am using a bash script. here i execute this code. This will return a output as Now i know how to store this entire output into a single variable and print it But i am not able to figure out how to store partial information into variable. Like if i want to store only TEST1 into the variable,

How to get 2 strings between certain characters in bash

String: I want to grab everything before the first instance of | and everything between External_SOC and ;PCRF. And store them as 2 different variables if possible. This gives me the following: 40125512ALPHA3 Answer EDIT: As per OP it needs to be done in a single line creation 2 of variables if this is the ca…

Linux bash ‘[: -ge: unary operator expected’ error

I tried this code and it gives many errors that could anyone help me to fix this problem please. Answer The source of the problem reported in the question is an empty decvalue as syme has already stated. Considering the purpose of the script, it seems you attempted to write a recursive function. For this reas…

Alternative to cron that retains environment variables

I have been trying to set up a cron job to run a bash script every 30 minutes on a Linux-based compute cluster. The problem is that some functions normally available in my shell are not available to the cron job, causing it to crash. I import all my environment variables (including the ~/.bashrc) but no luck,…

Remove part of file name in multiple sub directories

The main folder “Main” contains multiple subfolders (6900,159, 9997, …) and each subfolder contains 8 items (4 files (6900Log.final.out, 6900Log.out, 6900Log.progress.out, 6900SJ.out.tab), 3 folders (6900_STARgenome, 6900_STARpass1, 6900_STARtmp), and one compressed file (6900Aligned.sortedB…