A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.
Script are supposed to be smaller program, easy to write and useful for specific and daily tasks.
I have been looking at a few scripts other people wrote (specifically Red Hat), and a lot of their variables are assigned using the following notation
VARIABLE1="${VARIABLE1:-some_val}"
or some expand other variables
VARIABLE2="${VARIABLE2:-`echo…
There's a built-in 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 example,
% repeat 100 echo "I will not automate…
I want to have a script that takes the current working directory to a variable. The section that needs the directory is like this dir = pwd. It just prints pwd how do I get the current working directory into a variable?
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
#include
int main(int argc, char** argv) {
printf("%d", geteuid());
…
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 $file /some/other/path/$file;
read…
I would like to make an automated script that calls ssh-keygen and creates some pub/private keypairs that I will use later on. In principle everything works fine with....
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q
...except that it asks me for the…
I can read the numbers and operation in with:
echo "First number please"
read num1
echo "Second number please"
read num2
echo "Operation?"
read op
but then all my attempts to add the numbers fail:
case "$op" in
"+")
echo num1+num2;;
"-")
…
I have written a script that runs fine when executed locally:
./sysMole -time Aug 18 18
The arguments "-time", "Aug", "18", and "18" are successfully passed on to the script.
Now, this script is designed to be executed on a remote machine but, from…
I've seen this comment many times on Unix & Linux as well as on other sites that use the phrasing "backticks have been deprecated", with respect to shells such as Bash & Zsh.
Is this statement true or false?
I am new to bash script programming.
I want to implement a bash script 'deploymLog', which accepts as input one string argument(name).
[root@localhost Desktop]# ./deploymLog.sh name
here I want to pass the string argument(name) through command line…
I want to run a script to simply change the current working directory:
#!/bin/bash
cd web/www/project
But, after I run it, the current pwd remains unchanged! How can I do that?
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. I've read where they can be used in statements such as:
if […
I just saw this in an init script:
echo $"Stopping Apache"
What is that dollar-sign for?
My research so far:
I found this in the bash manual:
extquote
If set, $'string' and $"string" quoting is performed within ${parameter} expansions enclosed in…
How can I get the command arguments or the whole command line from a running process using its process name?
For example this process:
# ps
PID USER TIME COMMAND
1452 root 0:00 /sbin/udhcpc -b -T 1 -A 12 -i eth0 -p…
Is there an easy way to substitute/evaluate environment variables in a file? Like let's say I have a file config.xml that contains:
instanceId$INSTANCE_ID
…