Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

-2
votes
2answers
51 views

How to delete a directory from terminal?

I'm trying to delete a directory after a series of events take place. That being said, I need to be able to place this in a file to execute once said events take place.
4
votes
3answers
149 views

How do I read the output of commands in a script

I'm learning Linux scripting at the moment, and one thing I can get working is assigning a command output to a variable. The command service httpd configtest returns Syntax is OK, so I wrote this. ...
8
votes
2answers
113 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
0
votes
1answer
54 views

Can continually assigning a variable in a shell script cause a memory leak?

I've written a short script to copy Apache's server status to a log: #Save date and time to a variable dt=$(date) #Echo date and time to the log file as it's not included in server-status echo "Time ...
1
vote
0answers
24 views

Running a script after tty1 has loaded

I have been attempting to write a script to run dcled on start up, the program that runs this. I am using Debian Jessie with multiarch enabled. This is essentially a small file server. I am ...
4
votes
2answers
80 views

How to kill a process started as daemon?

I start a process using foo &. It outputs something like: [1] 16915 This is the process id, I guess. How can I store this number into a variable named MY_PROCESS_ID (for example)? Then I ...
8
votes
4answers
316 views

Using “${a:-b}” for variable assignment in scripts

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 ...
1
vote
1answer
26 views

mailx and HP-UX to RedHat migration

We are migrating some servers from HP-UX to Linux RedHat, and we have to migrate about 100 shell scripts that are referencing /usr/bin/mailx (instead of /bin/mailx on Linux). We'd like to change all ...
0
votes
2answers
89 views

Scripting Language Evolution [closed]

I have an assignment due Monday and I need some help because I have no knowledge on the subject and can't even understand what to search exactly. I am not waiting for an essay or something just some ...
3
votes
1answer
30 views

How can I tell whether a package is installed via yum in a bash script?

I am trying to write a script that installs packages, but if it fails at any point later in the script rolls back whatever it installed. Of course if the user has already previously installed a ...
8
votes
6answers
439 views

A bash function that takes argument like other languages?

I have a bash function to set the $PATH like this -- assign-path() { str=$1 # if the $PATH is empty, assign it directly. if [ -z $PATH ]; then PATH=$str; # if the $PATH does ...
0
votes
2answers
60 views

Bash split a list of files

I have 200 files in a folder like: test_1_cfg.dat, test_2_cfg.dat,.... and so on. I need to include in a bash script the first 40 files as input and run some process, another script to read the next ...
0
votes
1answer
38 views

How to pass a flag from one script to a function in another script

I have a script that installs a bunch of programs (homebrew, git, etc) and I have it log to stdout all the things that its doing along the way, but I want the ability to pass a flag, such as --no-log ...
3
votes
3answers
78 views

Bash, how to let some background processes run but wait for others?

I have (yet) another wait, &, && control flow question.. Say I have a script something like this where I want to do as much work at the same time as possible: # may take some hours ...
0
votes
1answer
31 views

Script in C shell skipping over last else statement?

This is a C shell script that checks the number of arguments and if the file/directory exists. When the arguments are valid, it should go to the last else statement and print "hi", but when I run this ...
-1
votes
2answers
75 views

Add users from dat file

I have a dat file with names. These are the names of users I must add, without groups or passwords. Ofcourse i have to remove all spaces. I have to add them with a bash script. Can anyone help me ...
2
votes
2answers
51 views

Unable to launch the requested CGI program: /www/cgi-bin/first.cgi: Text file busy

I'm trying to make a very simple shell script to run as a CGI on a uhttpd server running on an OpenWRT install. The file is called /www/cgi-bin/first.cgi and looks like... #!/bin/sh echo ...
0
votes
1answer
60 views

Scripting - Folders with spaces

I'm trying to write a script that's robust enough to work with spaces. Its currently in a for loop, but the problem I'm having is folders with spaces in its name. ASOURCE="Home Photos 2012 ...
8
votes
3answers
1k views

What does $# mean in shell?

What does $# mean in shell? I have code such as if [ $# -eq 0 ] then I want to understand what $# means, but Google search is very bad for searching these kinds of things.
1
vote
1answer
73 views

Divide a variable by a number? [duplicate]

Basically I need to convert centimetres to inches which I am trying to do by diving the area in centimetres by 2.54. But I just cannot get this to work. echo "please enter width and then height" ...
4
votes
2answers
106 views

Spliting `File` and `directory name with space' via shell script

I've got a file called Files.txt having following content: TestApp/Resources/Supporting Files/main.m TestApp/Resources/Supporting Files/AppDelegate.h TestApp/Resources/Supporting Files/AppDelegate.m ...
6
votes
4answers
385 views

How to run parallel processes and combine outputs when both finished

I have a bash shell script in which I pipe some data through about 5 or 6 different programs then the final results into a tab delimited file. I then do the same again for a separate similar dataset ...
0
votes
1answer
27 views

Where are RPM postinstall scripts located?

I have found a bug in an RPM that I have been provided. rpm -qp --scripts foo.rpm > /tmp/badscript cat /tmp/badscript postinstall scriptlet (using /bin/sh): ... if [ 'some bug' == true ].... I ...
0
votes
2answers
48 views

bash function output to pipe [closed]

I made a bash function to beautify svn output, this function show logs one line per commit, it is great! I like it, but if I use it with pipe it does not work. You can find it on github svn-beautify ...
3
votes
2answers
199 views

Range of the command cut in unix

I'm trying to make a shell script, I want to cut a string using the 'cut' unix command, as follows: namecmpaux=$(echo $namecmp |cut -c0-19) But when I run the shell tells me the following error: ...
2
votes
2answers
63 views

Shell Scripting: how to use part of the file path as the file name?

I have a group of directories, each containing exactly 1 jpeg image, like so- /psds/folder1/image.jpg /psds/someotherfolder/picture.jpg /psds/yetanotherfolder/thumbnail.jpg What is the appropriate ...
1
vote
1answer
72 views

Date calculation in script for notification alerts

I want to create account expiry alerts therefore I need to write a script which could alert me before 1 month of expiry over email. I'm working on Linux. I can get expiry information as 2015-27-03. ...
0
votes
1answer
77 views

Run smartctl on all disks of a server [Solved]

My question is a quite simple , I want to run the command smartctl -i -A on all disks that the server have. Think that I've too much server with different number of disks and RAID Controllers, then I ...
2
votes
1answer
36 views

Turning off default video output with xrandr when external monitor is connected

I'm new to bash scripting, and I'm trying to configure my video outputs so that my laptop display gets turned off when I connect an external monitor via VGA. That's the script I came up with, pretty ...
3
votes
1answer
54 views

Find and Replace Recursive

I want to modify every file in a directory recursively. I want to replace: <?php with <?php /** * * Copyright (C) MyCompany, Ltd. - All Rights Reserved * Unauthorized copying of ...
3
votes
2answers
71 views

shell script header for best compatibility [duplicate]

Which one is better: #!/usr/bin/env sh #!/bin/sh empty/no header I used to think the 1st one is the best, anyway i've found on some Linux-based systems (like Android) that pathname is missing, so ...
0
votes
2answers
54 views

why is ! character used in shell scripts [duplicate]

I recently encountered a situation where I tried to use ! as a record separator for my string array in shell script. When I used it in my shell script, the script got expanded automatically. An ...
10
votes
7answers
266 views

Test if multiple variables are set

I'd like to make sure that at a certain point of a script, after sourceing a configuration file, several variables are set and, if they are not, to stop execution, telling the user about the missing ...
-1
votes
2answers
24 views

how to get the return value of wpa_supplicant?

My question is really simple I want to get the return value of the command wpa_supplicant, when connected to the internet, to know that I am connected or not with a shell script.
4
votes
2answers
109 views

Convert every pdf in the current directory to png

I want to write a bash script to convert every .pdf file in the current directory into a .png file. For example: $ls . a.pdf b.pdf $./pdf2png.sh Converting pdfs to pngs a.pdf -> a.png b.pdf -> ...
4
votes
3answers
87 views

How to read user input in pipe?

Let's assume I have a file named confirmation.sh with the following content: #!/bin/bash echo -n "Are you sure [Y/n]? " read line case "$line" in n|N) echo "smth" ;; y|Y) echo "smth" ...
1
vote
1answer
64 views

For loop not getting executed correctly over ssh

I have a script in which I am reading from a csv file where it contains SourceIp, DestinationIP,Source Ports, Destination Ports. First I am reading the sourceIp and trying to do ssh over it (I am ...
2
votes
3answers
67 views

purpose of run-parts(8) utility

At least under Debian-based systems, there is a run-parts utility in debianutils package which is used in various scripts. For example in /etc/X11/Xsession. It will run all the executable files found ...
2
votes
5answers
298 views

How to reverse a string made of digit in bash?

What is the best way to turn out digits in number? E.g. $ echo 123 | hook 321 $ echo 12358 | hook 85321
2
votes
1answer
31 views

gnome-open execute shell script

Is there a way to execute shell scripts automatically using gnome-open? If I call gnome-open script.sh in the terminal, the script opens in the default text editor. However the shell-script is ...
3
votes
2answers
41 views

Bash script : help file inside the script or in a different file?

I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
1
vote
2answers
44 views

Bash script is not working

I wanted to create a script that executes the ls command with the provided arguments. Why isn't it working? I tried running it with for example -R, then it echoes (I echoed the same thing for ...
2
votes
2answers
50 views

I want a script which will take multiple column numbers from a user and reverse the contents

I want a Unix script which will take multiple column numbers from the user and reverse the contents. declare -a param="$@" # enter 0 when exit the insert element echo "Enter the numbers" read n while ...
11
votes
4answers
1k views

How Does Linux deal with shell scripts?

For this question, let's consider a bash shell script, though this question must be applicable to all types of shell script. When someone executes a shell script, does Linux load all the script at ...
2
votes
1answer
112 views

Bash Script getting stuck during execution

I have a bash script that is reading a CSV file , that contains source IP address , destination IP address and destination port. My script is basically doing 2 tests: 1 Performance 2 Connectivity. ...
4
votes
3answers
197 views

Check if 2 directories are mounted on the same partition on Linux

How can I check if /my/dir is on the same partition as /? This is for integration within a script. Bind mounts should be handled correctly. POSIX compatible solutions are welcome.
3
votes
1answer
176 views

Need help decoding bash script

Have following line in bash script, parsing input arguments: ((10#$2 > 0)) 2>/dev/null && shift 2 || shift Basically it helps handling parameters with optional integer subparameter. ...
2
votes
4answers
104 views

Parsing process command-line arguments from pargs in a shell script

I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to. At the moment I do it that way ...
0
votes
3answers
70 views

I want to create a zipped output file while keeping the original one

I am new to unix command and I have got one scenario that, I want to create a zipped output file while keeping the original one. I want to do it from Informatica end by using command task or session ...
1
vote
2answers
71 views

Supply input to a program with a password prompt

Is there any Linux command which supplies multiple enter keys to another process which is running in a terminal till the other process dies? For example consider the command yes ' ' | ./ssr-sim ...