Tagged Questions
The term 'shell' refers to a general class of text-based command interpreters most often associated with the Unix & Linux operating systems.
698
votes
26answers
432k views
22
votes
6answers
25k views
Capturing stdout when calling Runtime.exec
When experiencing networking problems on client machines, I'd like to be able to run a few command lines and email the results of them to myself.
I've found Runtime.exec will allow me to execute ...
281
votes
27answers
289k views
sed: How can I replace a newline (\n)?
I unsuccesfully tried:
sed 's#\n# #g' file
sed 's#^$# #g' file
How to fix it?
67
votes
11answers
46k views
Asynchronous shell exec in PHP
I've got a PHP script that needs to invoke a shell script but doesn't care at all about the output. The shell script makes a number of SOAP calls and is slow to complete, so I don't want to slow down ...
132
votes
21answers
143k views
Using getopts in bash shell script to get long and short command line options
I wish to have long and short forms of command line options invoked using my shell script.
I know that getopts can be used, but like in Perl, I have not been able to do the same with shell.
Any ideas ...
320
votes
19answers
339k views
How do I split a string on a delimiter in bash?
How do I split a string based on a delimiter in Bash?
I have this string stored in a variable:
IN="[email protected];[email protected]"
Now I would like to split the strings by ';' delimiter so that I have
...
86
votes
5answers
68k views
How to execute a command and get output of command within C++?
I am looking for a way to get the output of a command when it is run from within a C++ program. I have looked at using the system() function, but that will just execute a command. Here's an example ...
49
votes
9answers
98k views
How to run Unix shell script from java code?
It is quite simple to run a Unix command from java.
Runtime.getRuntime().exec(myCommand);
But is it possible to run a Unix shell script from java code? If yes, would it be a good practice to run a ...
365
votes
11answers
195k views
In the shell, what is “ 2>&1 ”?
In a unix shell, if I want to combine stderr and stdout into the stdout stream for further manipulation, I can append the following on the end of my command:
2>&1
So, if I want to use "head" ...
4
votes
4answers
7k views
Arrays, linked lists and other data structures in cmd.exe (batch) script
I was playing with cmd.exe, but in its help I didn't find any info, how to define arrays.
I have found, how to define simple variables:
set a = 10
echo %a%
But, I want to create arrays, linked ...
217
votes
10answers
248k views
how to use ssh to run shell script on a remote machine? [closed]
Could you please suggest me how to run a shell script on remote machine?
I have ssh configured on both machine A and B. My script is on machine A which will perform a task on machine B.
114
votes
10answers
42k views
Why do people write #!/usr/bin/env python on the first line of a Python script?
It seems to me like the files run the same without that line.
124
votes
19answers
89k views
Best way to kill all child processes
I basically want to kill a whole process tree. What is the best way to do this using any common scripting languages. I am looking for a simple solution.
151
votes
20answers
92k views
Why doesn't “cd” work in a bash shell script?
I'm trying to write a small script to change the current directory to my project directory:
#!/bin/bash
cd /home/tree/projects/java
I saved this file as proj, changed the chmod, copied it to ...
250
votes
16answers
72k views
Check if a program exists from a bash script
How would I validate that a program exists? which would then either return an error and exit or continue with the script.
It seems like it should be easy, but it's been stumping me.