A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.
39
votes
5answers
20k views
Allow setuid on shell scripts
The setuid permission bit tells Linux to run a program with the effective user id of the owner instead of the executor:
> cat setuid-test.c
#include <stdio.h>
#include <unistd.h>
int ...
22
votes
5answers
3k views
What Unix commands can be used as a semaphore/lock?
I want to run multiple Bash shell scripts in parallel. However, I want to avoid race conditions. What Unix commands are truly atomic that I could use for this purpose, and how can I use them?
5
votes
4answers
983 views
Automatically run commands over SSH on many servers
There is a list of IP addresses in a .txt file, ex.:
1.1.1.1
2.2.2.2
3.3.3.3
Behind every IP address there is a server, and on every server there is an sshd running on port 22. Not every server is ...
20
votes
7answers
26k views
Looping through files with spaces in the names?
I wrote the following script to diff the outputs of two directores with all the same files in them as such:
#!/bin/bash
for file in `find . -name "*.csv"`
do
echo "file = $file";
diff ...
5
votes
3answers
2k views
Storing output of command in shell variable
I have an operation using cut that I would like to assign result to a variable
var4=ztemp.xml |cut -f1 -d '.'
I get the error:
ztemp.xml is not a command
The value of var4 never gets ...
5
votes
3answers
2k views
What is IFS in context of for looping?
I'm learning bash scripting right now.
I was reading this thread: How to loop over the lines of a file?
What is IFS?
With for and IFS:
5
votes
5answers
411 views
Shell programming, avoiding tempfiles
I often write KSH shell scripts that follow the same pattern:
(1) retrieve output from one or more command
(2) format it using grep|cut|awk|sed and print it to the screen or to a file
In order to ...
98
votes
16answers
47k views
Repeat a Unix command every x seconds forever
There's a builtin Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat. For ...
22
votes
2answers
2k views
What does “3>&1 1>&2 2>&3” do in a script?
I saw this line in a script:
DEVICE=`dialog --inputbox "Festplatten-Laufzeit auslesen. Gebe Sie das
gewünschte Device an: " 0 70 "" 3>&1 1>&2 2>&3`
What is
3>&1 ...
18
votes
1answer
558 views
How to implement a horizontal cat? [duplicate]
Standard cat concatenates files line by line (row by row, if you will). I find myself needing a horizontal cat command more and more often recently; i.e. a command that takes a list of files and ...
15
votes
8answers
4k views
Object-oriented shell for *nix
Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question.
This question is somewhat related to this post on ...
7
votes
3answers
511 views
How to pipe the list of commands displayed by of “tab complete”?
When using commands in bash I like the double tab option to display the available commands. Some commands have more possible matches than others:
Is there a way I can pipe the output of the double ...
3
votes
2answers
568 views
How to do a text replacement in a big folder hierarchy?
I want to search and replace some text in a large set of files excluding some instances. For each line, I want a prompt asking me if I need to replace that line or not.
Something similar to vim's ...
6
votes
5answers
636 views
How can I have more than one possibility in a script's shebang line?
I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
5
votes
2answers
678 views
How to tweet using terminal?
I would like to tweet a message using terminal.
I tried something like:
curl -u 'TwitterUsername':'TwitterPassword' -d status=”Your Message Here” https://twitter.com/statuses/update.xml
but seems ...