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?

8 May at 19:51

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 : `...

1 Apr at 14:33

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...

10 Sep at 10:36

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...

12 Mar at 17:13

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?

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:

9 Dec at 22:33

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...

23 Sep at 23:49

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...

30 Oct at 10:58

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...

14 Mar at 16:47

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...

17 Feb at 06:7

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...

10 Aug at 00:19

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...

10 Apr at 02:51

How to get file creation date/time in Bash/Debian?

How to get file creation date/time in Bash/Debian? I'm using Bash on Debian GNU/Linux 6.0. Is it possible to get the file creation date/time? Not the modification date/time. `ls -lh a.txt` and `stat -...

12 Feb at 21:30

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...

21 Dec at 23:57

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...

2 May at 12:13

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...

30 Jul at 14:12

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/...

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...

22 Dec at 17:16

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...

30 Nov at 10:49

Saving awk output to variable

Saving awk output to variable Can anyone help me out with this problem? I'm trying to save the awk output into a variable. ``` variable = `ps -ef | grep "port 10 -" | grep -v "grep port 10 -"| awk '{p...

12 Mar at 11:42

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?

12 Feb at 07:55

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`...

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'...

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...

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...

23 Nov at 13:23