I’ve got a JSON list (the value of a key-value pair containing a list of items): [ “john”, “boris”, “joe”, “frank” ] How would I convert this to a bash array, so I can iterate over them? Answer Easy Case: Newline-Free Strings The simple approach is to use …
Tag: shell
How to add a word at the beginning of each line BUT not when a # is present
Given a file with many ENV variables. Example: DEV.env I know the command sed “s/^/export /g” will add export at the beginning of each line. But I don’t want to do this when the first character is “#”. How can I do with sed? Answer Something like this: Alternatives:
How do you move files from one folder to the other?
I am trying to move specific files from one folder to another. Would the below work? Answer I think this can work:
Linux shell script regex match
I have a text file. I want to get lines starting with specific format. I just want to get lines that have x/x/x format. x is a number. But this regex is not working. It is always giving no match : File is : Answer Don’t use bash if you can use a better tool: But if you have to
pipe command make standard input broken
I have two processes: t1.cpp and t2.cpp. t1.cpp and t2.cpp are simplified ,I want to describe the problem easily. After compiling t1.cpp and t2.cpp. I execute them in this way ./t1 | ./t2. Problems occur! cin >> x; in t2.cpp failed! I have no chance to type from the keyboard. It seems the pipe command i…
Prevent entering duplicate records in file using Shell Script
I am creating one sh file in which user enters the roll number, name, subject name and marks. And i am storing it in one text file. Now i don’t want the user to enter the same roll number again. If he enters the same roll number it should throw an message. Here is what i have done: How to
run shell script from php as a specified user
I am trying to run a shell script from a PHP script. PHP code : my shell script : After I run the PHP code in a web server (Xampp), I got this output : Although, I haven’t set any password for the daemon user. And after I checked the current user running the PHP code I found it is
Running a program on many different computers automatically
I am new to scientific computing and am working on a project which involves running many simulations. The infrastructure with which I am provided for this is about 20 different linux machines which all share storage. What I’ve been doing so far is the horrendously inefficient task of ssh’ing into …
Shellscript If statement returns error
I am trying to check if a file is older than 5 minutes and if that is the case I want to call another shell script which sends me a mail. check_file.sh: Error output: 3: ./check_file.sh: [1]: not found Answer Try something like:
SSH and exec channels with python shell
We have implemented a python shell for our hardware devices that solely consists of the python cmd module on embedded linux. Our (non-root) user’s shell is set to the path of this python shell in /etc/passwd and /etc/shadow. Code example below: Previously, one of our clients had used SSH.NET to issue co…