tagged [shell]
How to check if a file contains a specific string using Bash
How to check if a file contains a specific string using Bash I want to check if a file contains a specific string or not in bash. I used this script, but it doesn't work: What's wrong in my code?
Way to create multiline comments in Bash?
Way to create multiline comments in Bash? I have recently started studying shell script and I'd like to be able to comment out a set of lines in a shell script. I mean like it is in case of C/Java : `...
executing shell command in background from script
executing shell command in background from script how can I execute a shell command in the background from within a bash script, if the command is in a string? For example: this does not work -- how c...
Execute a shell function with timeout
Execute a shell function with timeout Why would this work but this wouldn't ``` function echoFooBar { echo "foo bar" } echoFooBar # foo bar timeout 10s echoFooBar # timeout: failed to run command `ec...
unary operator expected in shell script when comparing null value with string
unary operator expected in shell script when comparing null value with string I have two variables Here is my shell script code If I run this code it will prompt a warning How can I solve this?
- Modified
- 22 Mar at 15:15
How to declare 2D array in bash
How to declare 2D array in bash I'm wondering how to declare a 2D array in bash and then initialize to 0. In C it looks like this: And how do I assign a value to an element? As in C:
Use shell utilities for equivalent of SQL group by on a CSV file
Use shell utilities for equivalent of SQL group by on a CSV file I've got a csv file where the left most column contains an ID field. Is there a clever way I can use any utility programs such as sed t...
How to tell if a string is not defined in a Bash shell script
How to tell if a string is not defined in a Bash shell script If I want to check for the null string I would do but what if I want to check whether the variable has been defined at all? Or is there no...
How to run a bash script from C++ program
How to run a bash script from C++ program Bash scripts are very useful and can save a lot of programming time. So how do you start a bash script in a C++ program? Also if you know how to make user bec...
Using the passwd command from within a shell script
Using the passwd command from within a shell script I'm writing a shell script to automatically add a new user and update their password. I don't know how to get passwd to read from the shell script i...
Sorting a comma separated list of values
Sorting a comma separated list of values What's the easiest way to sort a comma separated list of values in Mac OS X: Input: "a, b, aaa, bc" Output: "a, aaa, b, bc" I'd like to do this from the termin...
How to cut first n and last n columns?
How to cut first n and last n columns? How can I cut off the first and the last columns from a tab delimited file? I tried this to cut first column. But I have no idea to combine first and last n colu...
How do I know the script file name in a Bash script?
How do I know the script file name in a Bash script? How can I determine the name of the Bash script file inside the script itself? Like if my script is in file `runme.sh`, then how would I make it to...
Convert decimal to hexadecimal in UNIX shell script
Convert decimal to hexadecimal in UNIX shell script In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feed...
How to run Unix shell script from Java code?
How to run Unix shell script from Java code? It is quite simple to run a Unix command from Java. But is it possible to run a Unix shell script from Java code? If yes, would it be a good practice to ru...
Redirect stderr and stdout in Bash
Redirect stderr and stdout in Bash I want to redirect both [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_.28stdout.29) and [standard error](https://en.wikipedia.org/...
- Modified
- 3 Aug at 09:51
how to remove the first two columns in a file using shell (awk, sed, whatever)
how to remove the first two columns in a file using shell (awk, sed, whatever) I have a file with many lines in each line there are many columns(fields) separated by blank " " the numbers of columns i...
Checking if output of a command contains a certain string in a shell script
Checking if output of a command contains a certain string in a shell script I'm writing a shell script, and I'm trying to check if the output of a command contains a certain string. I'm thinking I pro...
How do I extract a string using a regex in a shell script?
How do I extract a string using a regex in a shell script? I want to extract part of a string using a regular expression. For example, how do I extract the domain name from the `$name` variable?
Shell Script: How to write a string to file and to stdout on console?
Shell Script: How to write a string to file and to stdout on console? How to write a string to file and to `stdout` on console? If I do I view only `hello` in `logfile.txt` but how can I write `hello`...
- Modified
- 28 Mar at 13:24
How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?
How can I use inverse or negative wildcards when pattern matching in a unix/linux shell? Say I want to copy the contents of a directory excluding files and folders whose names contain the word 'Music'...
- Modified
- 19 Oct at 17:24
Multithreading in Bash
Multithreading in Bash I would like to introduce multithreading feature in my shell script. I have a script which calls the function `read_cfg()` with different arguments. Each of these function calls...
- Modified
- 21 Sep at 22:41
CTRL-C doesn't work on Java program
CTRL-C doesn't work on Java program I found a weird scenario where if I start a java program and I want to exit gracefully with + it doesn't work/respond, I have to do a + on the program and this is n...
- Modified
- 23 Nov at 13:23