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

learn more… | top users | synonyms (2)

1
vote
5answers
85 views

How to get all numbers out of a string and add them?

I have to parse a .xml file generated to summarize the results of a running a testSuite on some software. In a line I have, for example: <Summary failed="10" notExecuted="0" timeout="0" ...
3
votes
2answers
86 views

How do you know you are on the last line when looping through a file?

I have a file called listing.txt It contains data like: 1 2 3 4 5 I then use the following to loop through the file and do stuff with each line: IFS=$'\n' while IFS= read -r inc; do if [ ...
1
vote
1answer
39 views

Trying to store the output of file command into a variable , but the output says “no such file exists”?

This is my shell script: $EXTENSION=$(file $RADIOOUT) $RADIOOUT contains the file name along with its path. output is: ./zenityentry: line 40: =/home/jeevan/Downloads/p.txt:: No such file or ...
1
vote
3answers
73 views

how to break a line after matching a certain character using shell command?

File1: John Daniel Hommes Cameron;Emily Terry Mussy Barbara Mimi Papu;David Swiss Jen Hans Peter Iril;Kelvin Lilly Gucci Kate Nik;Forum Bill June;Jill and Jack Output file: John Daniel Hommes ...
0
votes
2answers
55 views

How to count the number of words of each sentences in a file using shell command?

I have text files like this: Mr.P.K.Baneerjee has visited the site today at 4.30pm The permit tag has been set in the ds busbar Opearation has been performed in presence of control engineer Opeation ...
1
vote
1answer
26 views

Bash script only runs in debug mode [closed]

I have the following bash script: #!/bin/bash -e SUDO=sudo $SUDO apt-get -y update || true $SUDO apt-get -y install lxc bridge-utils || true # remove the default bridge, if it exists ...
2
votes
1answer
24 views

How to tar-bzip old files in yearly groups

I wish to know a command I can use to grab and archive all files for a year at a time. I am working on a directory that has 72000 files, with files dated from 2007 to current. And I wish to make that ...
-3
votes
0answers
49 views

Bash Script for Renaming files

I need a shell script, which can rename all the files in the folder, Like Go into the designated folder, Search for all the files like Core.3467 core.1234 core.acde and change it to like ...
1
vote
3answers
72 views

Save a list of files over SFTP to a text file

I have provided my own answer below. We have a number of bash scripts that work fine using SFTP, what I would like to do is to simply re-direct an ls or dir of a folder to a file on our SFTP Server.. ...
1
vote
1answer
23 views

Send javascript to Chromium or Firefox from linux terminal

I am using either a chromium or firefox web browser in kiosk mode to log in to a website from boot up, and I want to use a javascript to send in a command to login to a website automatically. I know ...
-1
votes
2answers
78 views

check if string represents valid path in BASH [duplicate]

I currently have a directory in a string, as such: DESTDIR="/var/files/mydir/filedir/" Note that this directory does exist. I made sure of that. I need to check if this directory already exists, ...
0
votes
0answers
15 views

mkdir in shell script failing with \r [duplicate]

I have the following basic shell script: #!/bin/bash mkdir /var/lib/mysql/backups/test rm -r /var/lib/mysql/backups/* ROOTDIR="/var/lib/mysql/backups" TODAYDIR=`date +%Y%m%d` mkdir ...
0
votes
2answers
51 views

how to grep the file names based on the date formate

We have hourly and daily files in the same folder: data-2015-06-06-00.tsv data-2015-06-06-01.tsv data-2015-06-06-02.tsv data-2015-06-06-03.tsv data-2015-06-06.tsv data-2015-06-07-03.tsv ...
0
votes
3answers
66 views

How to achieve “continuos randomness”?

With RANDOM%xone gets a set of discrete results. How can I achieve following scenario?: Inside a for loop, I'd like to let a bash script execute command A in 33.33% of all loops and else execute ...
0
votes
1answer
41 views

Bash if statement not working properly [closed]

I have a bash statement to test a command line argument. If the argument passed to the script is "clean", then the script removes all .o files. Otherwise, it builds a program. However, not matter what ...
0
votes
0answers
5 views

Fine tuning of an informative replacement for rm [migrated]

I want to replace rm by a more informative variant: I would like to see which files will be deleted, along with their size, and I would like this information to use the same coloring as ls. I built ...
2
votes
4answers
61 views

How to parse table for pattern if pattern includes spaces

A continuation of this question: parse first column of command output, get corresponding second column value Say I have a command that outputs a string formatted as a table, as shown below. What if ...
4
votes
3answers
58 views

Go from a String to an Array of “words” in Bash

I need to go from a string to an array where each entry is each word on that string. For example, starting with: VotePedro="Vote for Pedro" I need the array: Vote For Pedro Which I should then ...
3
votes
3answers
50 views

Wait for key in shell script that may get piped to /bin/bash

Consider the following shell script echo foo; read; echo bar Running bash my_script outputs 'foo', waits for the return key and outputs 'bar'. While this works fine running it that way, it doesn't ...
1
vote
1answer
52 views

Exiting a script called from another script via SSH

Suppose that bash script X is being called within another bash script Y. If I directly execute script X on a local machine, after X's completion, the program exits to the terminal. However, when I ...
0
votes
1answer
28 views

Running a command on different shell

While reading the answers of question Can bash write to its own input stream?, I found following command runs on zsh but not on bash : print -z echo mnciitbhu 1 . Is -z is an extension to print ...
2
votes
4answers
115 views

How to influence a bash while loop with a timed global variable?

I have a while loop in a bash script which should do something different at the beginning and at every 5 second interval. Any previous loop is allowed to complete. The 5s interval is indicated by the ...
0
votes
1answer
51 views

parse first column of command output, get corresponding second column value

I am fairly new to BASH scripting for Linux. I am executing a command that outputs a table, as such: firstValue: a secondValue: b.y7 thirdValue: c-x-g 10:42 GMT Say I need the secondValue. I ...
1
vote
1answer
59 views

What does colon (':') in bash variable resolution syntax mean? [duplicate]

Could you help me decode this assignment: jvm_xmx=${jvm_xmx:-1024} Can't understand, what it does.
2
votes
1answer
60 views

Updating environment variable in a shell script

I am trying to update the value of an environment variable in a third party shell script. My OS is Oracle Linux Server release 6.4 (Red Hat Enterprise Linux Server release 6.4 (Santiago). I already ...
1
vote
2answers
246 views

How can I check how many files have been created in one week?

How can I check how many files have been created in one week? Situation: The system will create four files at every week, if the system is running normally. For example: A_08-07-2015.csv ...
-1
votes
1answer
35 views

No such file or directory error when attempting to run shell script upon startup of console [closed]

I'm trying to run a shell script upon startup in cygwin. I have added these commands to my .bashrc file: $ echo 'export MAIN="D:/dev/Main" >> .bashrc > echo '.MAIN/Env/tpsScripts/devenv.sh ...
1
vote
0answers
20 views

Build Script Help, Not Loading Modules

So I am writing a script to build and install Netcdf, but when I source it, it seems like some of the lines just are not running or are being skipped and I am unsure why. When I run the code line by ...
2
votes
2answers
83 views

Assign variable identifier in loop and echo its value

I hope this question is not a duplicate because I've been trying various ways to solve this problem but couldn't find any solution. I have a for loop in which I'd like to store a command output into ...
1
vote
3answers
73 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
1
vote
2answers
128 views

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed. The below script captures history ...
2
votes
1answer
45 views

How to read and do a min/max/avg from a NMEA stream

I have a weather station attached to my device spitting NMEA 0183 on /tty/USB0 I have alreeady sorted out how to parse the data and echo what I want in a script. What I need to do now is write the ...
0
votes
1answer
52 views

/bin/sh script error “arithmetic expression: expecting primary: ” + “ ”

ERROR: ./client-disconnect.sh: 22: ./client-disconnect.sh: arithmetic expression: expecting primary: " + " I just need to know how to fix it. It's for user accounting with OpenVPN. Script ...
0
votes
3answers
74 views

Extract numbers from a text file and place them in another file

I have a text file whose contents looks like this: ...
1
vote
4answers
73 views

optimize command with or and pipe to parse the output of ifconfig

I have this command line, but it's doubling the grep and awk ifconfig eth1 2> /dev/null | grep "inet " | awk '{gsub("addr:","",$2); print $2 }' || ifconfig eth0 2> /dev/null | grep "inet " | ...
1
vote
0answers
25 views

How can I use arptables to limit the number of outgoing ARP requests a second?

End goal: Make a script that will limit the number of outgoing ARP requests in a second using arptables. This is to have the ability to not trip the ARP-limiting feature on Cisco devices. I want to ...
1
vote
1answer
24 views

What's the Fedora equivalent of /var/lib/dpkg/info/[…].prerm?

Example file: /var/lib/dpkg/info/util-linux.prerm What's the Fedora equivalent of this file? (Not limited to util-linux - generic question for any package.) Use case: A prerm script is failing. ...
0
votes
1answer
101 views

How to execute R script attaching it to a shell script in Linux?

I am trying to submit a job to be executed on cluster. And this is done by writing an sbatch submission script. The job involves opening R 3.1.3 and running the referenced R script on the server. ...
2
votes
2answers
78 views

Sort files with a specific extension by modified time and store them into an array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
1
vote
2answers
33 views

Script to Compare the “file size” with “last name of file” and if unmatched delete the file

In my environment, we'll be receiving files from clients into our Sftp. Sftp process the files, and move it to another tool, by appending the file size at the end of the file name. For example, ...
8
votes
1answer
354 views

Are [ “$VAR” = “” ] and [ -z “$VAR” ] always equivalent?

My code looks something like this: VAR="" while [ -z "$VAR" ]; do VAR=$( command | grep "important_string" ) done So I want to poll the output of command, until the important_string appears and ...
0
votes
2answers
99 views

Explain the shell command: shift $(($optind - 1))

I am not a Linux guy but stuck in some Script which I have to read for my Project. So can anyone can help me what this command is doing? shift $(($optind - 1))
0
votes
4answers
92 views

The first Line of Scripting [duplicate]

what does #!/bin/bash at the 1st line mean ? Is it just a comment and ignored by the shell like all other comments in program OR Only this line is interpreted by the interpreter and all the other ...
13
votes
3answers
576 views

Differentiating between running and being sourced in a bash shell script?

Either what I'm asking here is extremely unorthodox/unconventional/risky, or my Google-fu skills just aren't up to snuff... In a bash shell script, is there any easy of way of telling if it is ...
1
vote
1answer
64 views

Pick columns from a variable length csv file

I have two CSV files, which share a column that is unique to each row in each file, like an ID. The files don't have a header. The file_2 has variable length columns e.g. 1,2,3 4,5,6,7,8 I joined ...
1
vote
1answer
54 views

validate the sequence number in the trailer of a file

We have a file that arrives daily and has a sequence number in the trailer like 9999 TR SAP _AP Distribution 0000000000000001 where 0000000000000001 is the sequence number and the file that ...
1
vote
1answer
51 views

Display a line in a text file if variable matches a part in the line?

I'm making a stock checker. I have a file with all of the NYSE exchanges and their descriptions. The descriptions start on the first tab enter of the file. The file formatting looks like this: A ...
1
vote
1answer
51 views

Find last line of a file for matching string?

I want a loop that runs infinitely over a file but always checks the last line to see if it contains the matching string if it does then echo that line and keep the loop running. What I have right now ...
-1
votes
1answer
45 views

Starting Debian mono application (that has a GUI) AFTER boot is done [duplicate]

I've been trying to figure out how to start an application after Debian (Wheezy) is done booting up and on an LXDE desktop session. It is a mono C# application. The script I have is simply mono ...
2
votes
2answers
72 views

Difference of using () and $() to execute a series of commands

I am currently trying to make a script that creates bytes that will be piped as input to netcat. Here is the idea of the script: (perl -e "print \"$BYTES\x00\"; cat file; perl -e "print \"More ...