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

learn more… | top users | synonyms (2)

2
votes
8answers
127k views

Adding two numbers using expr

I'm learning Shell scripting for a diploma in IT I'm currently doing. I'm trying to write a small script that adds two numbers as shown as in one of the tutorials we were given. echo "Enter two ...
2
votes
4answers
49 views

String Manipulation Shell Script [duplicate]

I am working on a UPS Monitoring project using NUT Server. My objective is to make a shell script which sends one command and in response receives the status and other parameters from the UPS. for ...
0
votes
2answers
22 views

Extracting a date from a log file and creating a file with unique dates

I would like to extract from a file the date with format DD.MM.YYYY, date is always in the first place, here an example of the entries 15.04.2016 13:13:30,228 INFO [wComService] ...
1
vote
1answer
36 views

Exiting a shell script if certain child processes exit

I have a Bash script that starts one web server, does some work, and then starts a second web server. I would like the script to exit, and for both of these servers to be terminated, if either server ...
2
votes
1answer
18 views

Set variable to random item in array

In bash, I have an array containing a list of links, e.g. http://xkcd.com/archive http://what-if.xkcd.com/ http://blag.xkcd.com/ http://store.xkcd.com/ I also have a variable named $URL. I would ...
3
votes
3answers
292 views

Sourcing a shell script from within Emacs

I would like to source a shell script that changes my environment variables from within Emacs. That is, I would like the shell script to change the environment in which Emacs runs, and I would like to ...
60
votes
5answers
193k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
0
votes
1answer
15 views

How to print ${STR1} and $STR2 into a file in bash

I need to print expressions ${STR1} and $STR2 into a file (not the content of the variables).How can I accomplish this using echo or printf?
1
vote
2answers
38 views

Extract zip files into directory based on pattern of zip name

I have these zip files: PLP_633555_2015-03-04_01-12-01.zip PLP_634562_2004-03-02_02-15-07_UBIC.zip PLP_563462_2008-05-02_01-21-03_UBIC_STOC.zip And I need each zip extracted into its appropriate ...
1
vote
1answer
42 views

Get run time for two programs simultaneously

I am trying to make a shell script that could run tests on two differents programs simultaneously and compare their runtime in order to see which one has the best efficiency (tests have to be ...
1
vote
3answers
137 views

Change directory working directory in shell script

I am trying to write a simple shell script, which will change the directory to the shell script directory and echo it. This is the script: #!/bin/bash # cd '/explicit/path/to/script' cd $(dirname ...
1
vote
3answers
113 views

Separating variable names from output strings with no whitespace

I have the following snippet of code where I intend to: Iterate 5 times the loop; get a line from a file (each iteration I need the next line fetched); use the line as a title for a file; put a ...
2
votes
2answers
58 views

Script execution failed

I have created a script to capture the heap and thread dump of a running java process. #! /bin/bash myhost=$(uname) if [ "${myhost}" == "SunOS" ]; then ...
1
vote
1answer
39 views

Detect number of /dev/sd_ 's on a computer by bash script

I am trying to add code to a Bash script (.sh) to detect the number of sd_ 's on a computer (ex. /dev/sda, /dev/sdb, /dev/sdc, etc.) and then save that number to a variable, and then use if statements ...
8
votes
3answers
25k views

Recovered deleted files on Mac by command line

I accidentally deleted a file by running: rm -rf ./Desktop/myScript.sh I think it's possible to recover the file, because the rm command removes temporarily. How can I recover the deleted file on ...
0
votes
1answer
49 views

Validate user response in shell script

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the ...
2
votes
2answers
26 views

Timeout with 'service network restart'

I have a script running on fedora 22 where I am restarting service network as part of a troubleshoot calling service network restart. I want to check if that command is taking too long to execute. If ...
0
votes
1answer
3k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
1
vote
2answers
47 views

Help me please to find my misunderstanding about this little piece of shell script

Actually, I have a folder which contains several sub folders with lots of images in each. I am trying to gather all the names of the files in each sub folder in a text file (filesNames.txt) in that ...
-2
votes
1answer
22 views

bash shell while loop is going beyond the conditional expression [on hold]

In my problem, it appears like j value and i value reach 6; where i should only run up to 5. Can someone please explain ? i=0; j=0; echo "values of $i and $j" > debug.txt; while [ $j -le 5 ] do ...
0
votes
0answers
31 views

How to do multi threading using mkfifo? [on hold]

I have a file which having milions of records like below. 8350000014|1234567|NULL|NULL 7336004920|478637|NULL|NULL 9876006473|478632|NULL|NULL 6730000012|1234567|NULL|NULL ...
11
votes
1answer
528 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
19
votes
5answers
21k views

find n most frequent words in a file

I want to find, say, 10 most common word in a text file. Firstly, solution should be optimized for keystrokes (in other words - my time). Secondly, for the performance. Here is what I have so far to ...
0
votes
1answer
1k views

CSH - How to check if input is NOT number

Please help, I can only see forums with this question for Bash, KSH, and others Need to apply it on csh. to check if the inputted $2 is not number nor the word "all" if ($#argv == 2 && ($2 ...
0
votes
3answers
154 views

Where can I find the shell script for ls command? [on hold]

I am trying to understand how the ls command works, and I presume there is a shell script which defines ls somewhere in the filesystem. This correct? If so, where can I find it?
2
votes
4answers
68 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
-4
votes
1answer
41 views

recursive script not working

I am trying to add recursive support to my filegrep script. For some reason this does not work as expected: RECURSIVE_MODE=off # iterate over args for ARG in "$@" do if [ -d "$ARG" ] && ...
1
vote
0answers
20 views

American Fuzzy Lop run test program as unprivileged user or in chroot

I'm attempting to test tcsh on OS X with American Fuzzy Lop as an exercise, but don't want to accidentally clobber any useful files on my system. Knowing essentially nothing about fuzz testing, I did ...
0
votes
0answers
15 views

Unable to execute the rest of my shell script after installing Oh My Zsh [on hold]

I thought that here it will be better to ask for help with my problem. In a nutshell: I'm creating my custom shell script to simply customise my Mac. To make a short example: 1) I install OMZ using ...
1
vote
1answer
26 views

bash script trap for exit and err and logic for difference

I have a bash script and would like to add in the ability to trap for both EXIT and ERR conditions. The structure is currently trap cleanup EXIT function notify(reason) {} function build {} function ...
10
votes
1answer
148 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
2
votes
3answers
53 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
3
votes
2answers
2k views

Joining bash arguments into single string with spaces

I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string. ...
3
votes
2answers
58 views

How can I parse an ini file whose values may contain certain characters?

I have looked at a couple bash ini parsing scripts and I've seen this one used a few times here so I'm trying to see if it will work for me. It looks like it reads the ini file line by line multiple ...
0
votes
1answer
29 views

small error but seems annoying [duplicate]

I have error (command not found). I am newbie here. so what is the easy solution and explanation for this error?
1
vote
4answers
155 views

Extract substring with character instead of position

I recently got into nautilus scripts, and for the one I'm writing I'd need to extract a substrong from a filename. My problem is that I found tons of methods to extract a substring based on the ...
-1
votes
2answers
35 views

Need help with script for regular expression in bash

Using bash shell I have a regular expression which works fine on data. How do I write that regular expression to segregate data into 3 different cols in bash shell script ? Here is the Regexpression ...
0
votes
1answer
28 views

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily: #!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect ...
13
votes
2answers
2k views

How to safely pass variables to root-enabled scripts?

This question is totally general and not only applicable to my situation, but... I have a small busybox appliance where I want a non-root user to be able to execute a particular script with root ...
0
votes
1answer
36 views

Run Concurrent Instances of a Command Inside a Shell Script

Let me start this by saying that I'm still learning bash scripting and I'm not aware of many things. If I miss something, feel free to scold me as you please. Onward, I'm creating a simple bash ...
3
votes
3answers
68 views

Replace a long string with the sed command: Argument list too long error

I'm trying to execute this command sed -i -e "s/BASE_64/$BASE_64/" FILE_NAME where $BASE_64 is a base 64 representation of a file content. sed gives me an error since the string is too long. ...
-2
votes
2answers
46 views

find all jpg images from specific directory and copy it to other directory

How do I copy all the jpg images [files whose names end with .jpg] that exist in the directory /usr/share/backgrounds into to the jpg directory in /week/pictures/final/jpg then redirect any error ...
0
votes
1answer
59 views

inserting modified date into filename - 2 cases

I believe I'll ask two separate questions, but the context is the same, so I hope it's alright. I have an output of few processes as presented below (which I can't modify). 25978.csv 26044.csv ...
1
vote
4answers
53 views

How to gather the name of the files in each subdirectory into a text file in that subdirectory?

I wanted to save the names of all files in each sub directory into a text file in that sub directory, so I wrote this script: #!/bin/bash for X in "$PWD" * do if [ -d "$X" ]; then ...
1
vote
3answers
94 views

How can I compare different files without opening them?

I have two directories A and B; each one contains a lot of sub-directories geom001, geom002 ....etc each sub-directory contains a file named results. I want to compare, without opening any of ...
0
votes
0answers
19 views

Systematically change all visible color in multiple pngs via a script?

I have a large set of pngs to be used as icons for an application I am developing. The icons are all a single color and have a transparent background. Is there a systematic way to change the single ...
0
votes
1answer
45 views

Why would this script work with bash on Kali, but not with bash on Xubuntu?

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I'm at work on my Xubuntu install and it's not working at all. The exact shell that I'm ...
0
votes
1answer
19 views

Why does the jobs command not work in shell script?

If I run jobs -l on command prompt it shows me the status of running jobs but if I run below file ./tmp.sh #! /bin/bash jobs -l It shows empty output. Why is that and how can I obtain information ...
3
votes
5answers
2k views

how to check directory is empty

I have a requirement, if I execute a script ./123 with an arguments of empty path, say /usr/share/linux-headers-3.16.0-34-generic/.tmp_versions(this directory is empty). It should display "directory ...
0
votes
0answers
37 views

sed can't find file on a shell script [duplicate]

I've been running into a problem whenever I run the shell script containing a sed. If I try this argument by running the shell script with the following line, it gives me a bizarre error: arg=$1; ...