Tagged Questions
A shell script is a script written for the shell, or command line interpreter, of an operating system.
1
vote
3answers
61 views
Evalute passed in variable in bash
Is there a way to pass in a variable as an argument to a bash script and have it evaluated scoped by the bash script?
Given:
# cat /path/to/file/of/host/names
bob
tom
joe
etc...
# dofor
FILE=$1
...
9
votes
5answers
128 views
Correct locking in shell scripts?
Sometimes you have to make sure that only one instance of a shell script is running at the same time.
For example a cron job which is executed via crond that does not provide
locking on its own (e.g. ...
3
votes
2answers
32 views
Ignore escape characters when printing string in shell script
I just wrote a simple shell script to save a LaTeX expression as a PNG file. It works fine, except for the LaTeX-syntax for "next row", i.e. the double backslash \\.
When for instance my input ...
6
votes
2answers
138 views
bash: Piping for loop output prevents local variable modification
First off, sorry for the title. I'm not sure of the correct terminology so if anyone can improve upon it that would be good.
I am trying to write a simple bash function that takes, as it's arguments, ...
1
vote
1answer
44 views
Using nohup at /etc/init.d/service
I have been trying to create a daemon using /etc/init.d/myservice and it will call a shell script that contains nohup within the script line.
Will it affect it if I could do service stop later?
3
votes
4answers
174 views
Is there a way to sum up the size of files listed?
This is the command I am using to list some files:
find . -name \*.extract.sys -size +1000000c -exec ls -lrt {} \;
-rw-r--r-- 1 qa1wrk15 test 1265190 Sep 29 01:14 ...
7
votes
1answer
225 views
How do you omit “./” when running scripts on current directory
On some tutorials over the internet they can run a script on the current directory without doing:
./script
How do you omit this? I am using CentOS 5.6 x64. I want to run it this way
script
3
votes
2answers
74 views
Print shell arguments in reverse order
I am a bit stuck. My task is to print the arguments to my script in reverse order except the third and fourth.
What I have is this code:
#!/bin/bash
i=$#
for arg in "$@"
do
case $i
in
...
10
votes
1answer
128 views
Execute bash scripts on entering a directory
What is the best way to execute a script when entering into a directory? When I move into a new directory I would like bash to execute the projectSettings.bash script much like RVM does.
10
votes
1answer
171 views
How to generate a lot of (blank) images files?
For a test, I need to quickly create 1700 jpg-images (even blank) in a defined size 1000x706. I wonder if we could do this with a shell script or a program (like ImageMagick). I wish they called ...
3
votes
3answers
69 views
Error handling in shell script
I wrote a shell script run_script.sh, which includes a step which creates an empty file run_script.lck. Everytime the shell script was called by the cronjob, it will check for the existence of ...
1
vote
1answer
61 views
How does this bash function work?
I'm looking at this short example, and I don't see how this function works:
function EXT_COLOR () { echo -ne "\[\033[38;5;$1m\]"; }
AFAIK -ne stands for not equal. What are we comparing here? I ...
2
votes
2answers
44 views
Unatended script execution in ubuntu terminal
I have installed Ubuntu on a VMWare virtual machine.
When I got to installing a VMWare tools, I have stumbled upon a simple question:
If I execute a script (perl script in VMWare tools case), is ...
1
vote
1answer
31 views
Allow www-data to execute a a script
I am trying to execute a script that will read a file written by PHP. The problem is that the script opens and some other files (C-ISAM file based database) and i have no clue what permisions to give ...
3
votes
3answers
85 views
How do I handle switches in a shell script?
Are there some built-in tools that will recognize -x and --xxxx as switches, and not arguments, or do you have to go through all the input variables, test for dashes, and then parse the arguments ...