Tagged Questions
31
votes
5answers
16k 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 ...
15
votes
3answers
2k views
How do I exit a script in a conditional statement?
I'm writing a bash script where I want to exit if the user is not root. The conditional works fine, but the script does not exit.
[[ `id -u` == 0 ]] || (echo "Must be root to run script"; exit)
...
14
votes
6answers
990 views
The most universal scripting language for Linux is?
We are writing scripts for Linux systems, there has been some debate over what would be the most universally Linux present scripting language to use. Bash, SH, Posix? What?
12
votes
6answers
3k 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 ...
12
votes
3answers
3k views
Answer yes in a bash script
I'm trying to do a git clone trough a bash script, but the first time that I run the script and the server is not known yet the script fails. I have something like this:
yes | git clone ...
11
votes
7answers
1k views
Practical tasks to learn shell scripting
I'm looking for some common problems in unix system administration and ways that shell scripting can solve them. Completely for self-educational purposes. Also I'd like to know how would you go about ...
9
votes
2answers
861 views
Confusing use of && and || operators
I was skimming through an /etc/rc.d/init.d/sendmail file (I know this is hardly ever used, but I'm studying for an exam), and I've become a bit confused about the && and the || operators. ...
8
votes
4answers
1k views
What are good online resources for learning shell scripting?
I am a beginner to shell scripting. I have not yet hardly coded a single program, but I am interested in learning it completely. Can anyone suggest some good online resources which will guide me?
7
votes
1answer
561 views
confirmed exit using trap
I am trying to trap the Ctrl+C signal asking a confirmation from the user. The trapping part works fine. But once the signal gets trapped, it does not return to the normal execution. Instead, it quits ...
6
votes
3answers
1k views
How to “send” variable to sub-shell?
I run the following script:
VAR="Test"
sh -c 'echo "Hello $VAR"'
But I get :
# ./test.sh
Hello
How can I "send" the variable VAR of my script to the shell created with sh -c?
6
votes
2answers
883 views
List elements with spaces in zsh
I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
5
votes
3answers
3k views
Processing bash variable with sed
Been banging my head off a wall on this
bash variable LATLNG contains a latitude & longitude value in brackets like so
(53.3096,-6.28396)
I want to parse these into a variable called LAT and ...
5
votes
3answers
1k views
How to run a script from another path, and know the script's path?
I need to run a script that access a file in the same path it is located.
For example: I have the script in /home/me/folder/script.sh, and this script will access the file /home/me/folder/myfile. As ...
5
votes
5answers
340 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 ...
5
votes
2answers
465 views
How does bash interpret the equal operator with no surrounding spaces in a conditional?
The following script does not behave as I would have expected. Adding spaces around the '=' in the conditional made it perform how I wanted, but it got me thinking, what is it actually doing inside ...