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

learn more… | top users | synonyms (2)

0
votes
1answer
19 views

Bash script hangs on specific input

I am trying to write a simple script which does something if the first parameter of the input is equal to the -r string. But whenever I try to run this file, the program hangs and I have to terminate ...
9
votes
9answers
310 views

How to get the last argument to a /bin/sh function

What's a better way to implement print_last_arg? #!/bin/sh print_last_arg () { eval "echo \${$#}" # this hurts } print_last_arg foo bar baz # baz (If this were, say, #!/usr/bin/zsh instead ...
1
vote
1answer
53 views

get first CLI argument after the options in shell scipt

I have a script I class like so gitploy up -t 2.0.0 test_repo. I pull out the "action" up right away, then I need to be able to get the test_repo before I process the options. I don't want to lose ...
1
vote
1answer
24 views

Breaking out of a loop, return to start of loop with correct value of variable

I am sending processes to a server, but I only want a certain number running at a time. Thus I loop which checks how many jobs are running and only submits new one if the current amount of jobs do not ...
0
votes
1answer
21 views

Trying to find the index of an entry in a list [duplicate]

I am trying to find the index of an list entry using this simple method: #!/bin/sh partList="500 1000 2000 4000" a=( $partList ) echo ${a["500"]} this returns Syntax error: "(" unexpected. And the ...
-1
votes
2answers
26 views

Script not running! Also how to attach timestamp in mail?

I have the following bash script... #!/bin/bash # Delete JUNK temp folder if [ -d JUNK/FOLDER/PATH ] then rm -rf JUNK/FOLDER/PATH echo "Cleansed JUNK directory successfully!" /usr/bin/mail -s ...
0
votes
1answer
43 views

set date time from user input in shell

I am creating script to check RTC working & for that first I am getting the date & time from user input in yyyy mm dd hh:mm:ss format. read -p "Enter the date:" val echo $val date -s "${val}" ...
1
vote
1answer
42 views

Why do I get the message set no match when I run this script?

#! /usr/bin/tcsh -f set ps_output = "`ps -u $user`" @ i = 2 echo "$ps_output" set ps_test while ( $i <= $#ps_output ) set line = ( $ps_output[$i] ) if ( $line[4] != "ps" && ...
0
votes
2answers
31 views

How to assign a multiple line string value to a variable with indentation in a shell script?

I want to assign the following multiple line string value to a variable in a shell script with the the exact indentations and lines. Usage: ServiceAccountName LogFile Where: ServiceAccountName ...
0
votes
1answer
31 views

What are conditions I can check for detecting error in downloading using bash?

I want to continuously download a link until it successfully downloads, #!/bin/bash while [ some_condition ]; do curl my_url # or vagrant add my_vagrant_url ...
0
votes
0answers
13 views

How to generate total size of files from each unique source in bash

I have a large number of directories which each contain files with the format unimportant_data_here_source_date.gz I want to calculate how much data came from each source. That means figuring out ...
1
vote
1answer
25 views

How to programatically send break signal (Magic SysRq) through serial terminal

I have following setup - I have 2 computers connected by serial connection (null modem) emulating vt220. I'd like to send break signal (Magic SysRq) from shell script - is it possible without writing ...
1
vote
0answers
35 views

Bold and Underline using echo with email

I am using a script that emails me a particular status report. The script sends me the contents of several files. I am using echo to provide a heading in the email that is used to differentiate ...
2
votes
1answer
73 views

How to get filenames when using find and sed

I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified. This is how I am finding and then using sed: find . -type f -a ...
0
votes
0answers
36 views

How do I redirect the output which is generated in that new terminal

I am trying to redirect the output from a newly invoked terminal to a file. But I don't know what the problem is with this code. Nothing is displayed in the new terminal. #!/bin/bash xterm -hold -e ...
0
votes
1answer
30 views

Can someone please explain this error I'm getting in my script

I'm trying to create a script which I can set as a cron job which adds all my dotfiles to a folder I've set up as a github repo then push them every evening. My script is the following. cp ...
0
votes
1answer
49 views

Using sed on files with certain extension inside shell script

I am trying to use sed to find files with certain extension and then replace occurrences of a certain string with another. No directory mentioned using current directory *.h sed: can't read *.h: No ...
1
vote
0answers
51 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
4answers
52 views

Change dir from script without a “shell procedure” or “sourcing the script”

I know what I can make a shell procedure or source the script instead of running it to cd the shell I am using. What I want to know is there any way to cd the "parent shell" (not sure if that is the ...
1
vote
0answers
20 views

Piping to 'tee' commands prevents changes in environment variables

I have a csh script using which I modify certain environment variables and echo values of these environment variables from within this script. I source this from another script: source ...
6
votes
3answers
1k views

Executing mail command from inside a function causes a “fork bomb”

When I try to execute mail from inside a function in a bash script it creates something similar to a fork bomb. To clarify, this creates the issue: #!/bin/bash mail() { echo "Free of oxens" | ...
0
votes
1answer
37 views

How can I get many addresses from many trajectories with bash script without error?

I have many trajectories data. 500k. I try to get adresses of these coordinates. I use bash command in linux. #!/bin/bash filename="$1" while read -r line do uid=$(echo $line | cut -f1 -d,) ...
0
votes
1answer
22 views

cannot reload .profile from script

I am trying to reload .profile from the below script, but that doesn't work at all. #!/bin/ksh sed -i '/export rel=Rel1510_Linux/c\export rel=Rel1602_MX' ~/.profile source ~/.profile When I run ...
0
votes
1answer
40 views

bash script : How to backup /user/home?

I'm currently studying scripting and I need to create a script to backup the /user/home using .bz2. I need the script to verify if the user exists and if there was no user selected to backup. ...
3
votes
7answers
320 views

Check if shell variable contains an absolute path

I want to check if a shell variable contains an absolute path. I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute ...
0
votes
1answer
27 views

How do I remove a . from the start of a Bash string and write the result to a variable? [duplicate]

I am presently writing a shell function and it would help me in writing it to be able to remove a . from the start of a folder name (changing the folder name from that of a hidden folder to that of a ...
1
vote
2answers
33 views

How do I keep command options from breaking other scripts executed within my command?

I have a bash shell script(my_script.sh) which runs a script(their_script) during execution. My script (my_script.sh) looks like this : THISDIR=`dirname $(readlink -f $0)` main() { cd $THISDIR ...
1
vote
2answers
42 views

How to select a row with latest date and time

I have a text file (space as delimiter) as shown below: Date Time---------OtherFields-------Source IP Destination IP 2014-11-24 12:58:59.290 1.2.3.4 ...
0
votes
0answers
51 views

sort files twice

I have a series of 300+ files that I need to sort twice, once by the date and a second time within that date by part of the filename. The only standard in the names is that ends with *mmddyyyy<time ...
1
vote
2answers
31 views

Cat all files in a folder including filename by using a for loop?

With this for loop which I execute directly in the shell, I am able to cat the contents of all files in a folder, with the value beside of it: $ for f in *; do echo -e "\t"$f"\n"; cat $f; done ...
1
vote
2answers
46 views

Getting list of corrupted file from folder and its sub folder

I have directory say folder which has sub-folders according to date like 01, 02, 03 and so on and each sub-folder has four directories called test1, test2, test3, test4 and all this directory contain ...
0
votes
1answer
24 views

Conditionals do not work in . ./script [closed]

I am trying to make a history file manipulations scripts. When I try to, for instance implement an incognito mode by running unset HISTFILE It doesn't work due to command running in new shell. ...
1
vote
3answers
122 views

Read a file line by line and if condition is met continue reading till next condition

I have a file foo.txt test qwe asd xca asdfarrf sxcad asdfa sdca dac dacqa ea sdcv asgfa sdcv ewq qwe a df fa vas fg fasdf eqw qwe aefawasd adfae asdfwe asdf era fbn tsgnjd nuydid hyhnydf gby asfga ...
2
votes
2answers
58 views

How to copy image files whose names don't end with their resolution size?

I have a folder with images in it and it is organized by year and month folders (ie. /2015/08/image.jpg). Whenever an image is added, it is also copied and resized like so: image-1024x768.jpg ...
0
votes
2answers
22 views

command to put hyphen in the second column if the space is given between a word [closed]

Suppose you have a file called test.txt with data like: you wel come how nice what do ing How can I add a hyphen in the second column if the space is given between a word?
2
votes
1answer
63 views

Tracking where the script stopped after timeout

I've got a shell script doing connection performance test, that I timeout if it takes too long. Upon timeout, it logs the results of a few commands so I can make myself an idea of the system status ...
1
vote
2answers
361 views

What is the meaning of a trailing “:” (colon) in *nix? [closed]

I am currently following a tutorial about shell scripting located here: http://www.cs.columbia.edu/~sauce/tutorial/ashell.html and I believe my script matches that one exactly. However, when I try to ...
0
votes
1answer
37 views

Identifying duplicate fields and REMOVE both with awk

Previously, I asked the question: Identifying duplicate fields and print both with awk. I have a file with multiple columns and wanted to identify lines where specific column values (cols 3-6) had ...
1
vote
2answers
47 views

How to execute a command randomly over a given time interval?

I am interested in a running a Unix command once randomly over a given time interval. For example, if the command is ls and my time interval is between noon and 2pm, how could I start a background ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
1
vote
1answer
21 views

Pause (with read or similar) in xargs

I have a script that looks something like the following. find /path -type f | sed -re 'stuff' | xargs -Ix sh -c '{ echo "information about x" ./exe < x read }' My goal is to provide each ...
-3
votes
7answers
107 views

Is there a way to prevent sed from interpreting the replacement string? [closed]

If you want to replace a keyword with a string using sed, sed tries hard to interpret your replacement string. If the replacement string happens to have characters that sed considers special, like a ...
5
votes
6answers
175 views

Take grep value and output the count and the value together

I am trying to make a bash script that greps value and output the count and the value together Something like this grep -c 'Thenis' example.txt > example.lst But in that list file not only to ...
0
votes
2answers
41 views

Sort words in file

i've got some problems i'm not capable to overcome. I need to count the first let's say N words in a txt file. Then , i have to print them in decresing order, followed by the number of occurences.The ...
0
votes
0answers
33 views

Updating/compile sendmail script not working.

I have wrote a script to update sendmail and compile on unix system I put those lines if [ ! -e $CWD/src/$NAME-$VERSION.tar.gz.sig ] then echo "$NAME-$VERSION signatures missing" wget -c ...
1
vote
0answers
18 views

How to count nodes and get attribute value without using xpath

Currently I have a shell script like this: LOGIN=`curl 'https://www.ponta.jp/u/LWAS900/SLWAS900010.htm' -sS | grep '<input type="hidden" name\|<form\|</form'` for i in $(seq $(printf ...
3
votes
1answer
83 views

List of VBox Machines Help?

So, I'm writing up a bash script to list out the VM's on my host, so I can make sure they are fired up when the host machine restarts... no problem here... my issue is getting the list of the ...
1
vote
0answers
44 views

Error “dircolors: no SHELL environment variable, and no shell type option given”

Running Linux Mint 17.3 Cinnamon A while ago a created a script that changed the colors in the Terminal (to match a tutorial I was following) However if I open the terminal on another account, I get ...
1
vote
1answer
46 views

Exporting Variables and setting Global Variables in Bash [closed]

My objective is to create a list of variables that can be called or referenced by any test script that is being executed. There are a lot of test scripts on the system but the variables are ...
2
votes
3answers
49 views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of ...