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

learn more… | top users | synonyms (2)

2
votes
1answer
2k views

download pdf files from using curl

How to download hundereds of .pdf files from http://www.ncbi.nlm.nih.gov/pmc/articles using a loop, for example for the following document ids: PMC3386155 PMC3625956 PMC3477654 PMC3531051 ...
2
votes
3answers
712 views

Exception handling when using tail -f to monitor a log

I have a main script calling the script to do the monitoring. I am trying to catch the exception that the log is missing or not accessible anymore. tail -f is used instead of -F since the logs are ...
2
votes
2answers
62 views

How to paste same information into 2 different files?

I'd like to create two files in /etc/skel using a script which does many other things in addition to the creation of the files in /etc/skel. The part from script regarding /etc/skel looks like this: ...
2
votes
2answers
129 views

how to count number of differences in large streams quickly?

I want to count the number of differences (different bytes) in two large streams (devices/files). E.g. two hard disks, or one hard disk and /dev/zero. The program(s) involved must be fast, as fast ...
2
votes
1answer
478 views

Bash: pair up two series of files

I have a number of files with this pattern: file1_foo.ext file1_bar.ext file2_foo.ext file2_bar.ext and so on. I need to "pair them" and put them in a file like this file1_foo.txt file1_bar....
2
votes
1answer
370 views

Difference between two types of shell arithmetic

What is the difference between the following two shell arithmetic commands: echo $[ $var1 - 1 ] echo $(( $var1 - 1 )) Assuming var1 = 5 for example.
2
votes
1answer
5k views

sed special character replace not working in shell script

I want to write a script 'test.sh' that will take a user's input and replace all special characters with a '\' + the character. My script: #!/bin/bash echo 'input='"$1" arg=`echo "$1" | sed 's:[]\[\^...
2
votes
1answer
5k views

How to add header and footer to the flat file

I need to add a header and a footer to flat file - I just need to get values from the parameter like system date and report run date in the top line and for the footer I need to get the record count ...
2
votes
1answer
564 views

How to capture text formatting in bash?

The following shell script works but removes colored formatting generated by rspec: #!/bin/bash OUTPUT=`rspec` echo "$OUTPUT" How to preserve the colors?
2
votes
1answer
2k views

How can I set environment variable permanently through shell script?

Let's say I have a script: #!/bin/bash echo $1 if [[ ! $1 ]];then echo "True" fi export ABC="/home/aashish" ABC is not available after the execution of this script. How can I make that variable ...
2
votes
1answer
2k views

Send email from a shell script

I have written a script which runs a simple program in the background, logs the output and emails me when the job is done. It works fine except for the fact I am not recieving the email. I have tried ...
2
votes
2answers
377 views

How do I add an if statement (regarding punctuation in a word) to this bash script

I have this bash script #!/bin/bash cat $@ | while read line do for word in $line do echo $word | circling-the-square # here's where i need to add the if statement: #...
2
votes
2answers
277 views

bash script with network request in pure lsb environment

From what I can understand of LSB documentation, neither wget or netcat are standard tools always available in an LSB environment. Is there some other way to make a http request without being ...
2
votes
2answers
835 views

Shell script output incorrectly splitting while being passed as an argument to script

Let's say I have the following two shell scripts: #!/bin/sh #This script is named: args.sh echo 1 "\"Two words\"" 3 , and: #!/bin/sh #This script is named: test.sh echo "Argument 1: "$1 echo "...
2
votes
1answer
183 views

Files with no .sh extension not considered for autocompletion in zsh

I have noticed that unless I add an .sh extension to my shell scripts, Zsh does not suggest them for autocompletion for execution despite having them in my PATH. I have the same problem if I cd into ...
2
votes
5answers
7k views

script to scan ip range and return results in a certain format

This script scans IP's and returns a status of Up or Down. How can I alter it so it doesn't scan everything twice? As it sits it scans everything and returns the "Up" addresses only and then scans all ...
2
votes
4answers
1k views

Is there any handy command line tool to manage Cron jobs?

Would someone suggest any handy command line (NOT web) tool or script which adds, enables and disables Cron jobs? I am looking, for example, for the following (or similar) behavior: sh manageCron.sh -...
2
votes
1answer
869 views

How do I replace certain text with the respective line number using sed?

I have a file where certain (not all) lines look like so: Sequence: n I wish to replace n with the respective line number. How can I do it with sed?
2
votes
3answers
11k views

What is the default shell for .sh in AIX?

I am fairly new to AIX machine. We would like to deploy some program into the AIX machine which is yet to come. We have a short experience in AIX machine and after login using putty, we felt the ...
2
votes
2answers
2k views

How to build a long command string?

I've a sequence of commands to be used along with lot of pipings, something like this: awk '{ if ($8 ~ "isad") {print $2, $5, "SE"} else {print $2, $5, "ANT"} }' "/var/log/apache2/other_vhosts_access....
2
votes
2answers
24 views

Resize image in a script using Imagemagick

I'd like to create a bash script to resize images up to 800px keeping proportion... My code doesn't work in bash, but it works using identify with a single image : #!/bin/bash for file in ./**/...
2
votes
2answers
58 views

How to assign value to input variable in shell

I am asking user for input and taking input in the variables such as $1, $2 etc. I am checking the variable for null value and wants to replace the value if null. if [ "$2" == "" ]; then 2=value fi ...
2
votes
1answer
423 views

How do I get bash to give a relevant error for a file with windows line-endings?

Suppose I have the following shell script: #!/bin/bash \n echo "Hello World" \n Running it gives Hello world. Now suppose I have the following shell script #!/bin/bash \r\n echo "Hello world" \...
2
votes
1answer
22 views

Strings from two distinct arrays not matching?

I'm trying to filter one array from another array. That is, I'm trying to create a third array with a logical not-intersection. The best I can tell, it appears this block of code never matches, and ...
2
votes
1answer
40 views

Source of “gsed: can't read : No such file or directory”?

I have a Bash script that performs a simple substitution on OS X. Here's the reduced case: mkdir vs2005-dynamic cp cryptdll.vcproj cryptest.sln cryptest.vcproj cryptlib.vcproj dlltest.vcproj vs2005-...
2
votes
2answers
92 views

search contents of files that are packed in a zip file

For my school project i have to create a script that allows you to search the contents of files that are packed in a zip file. You can give a "search string" with the script, followed by one or more ...
2
votes
2answers
113 views

what is the difference between “./command” and “bash command”

I have simple bash script file, it contains only one line: rvm gemset use --create 2.0.0@PRJ_NAME If I run this script with: ./scriptname.sh I get a well-known error message from RVM RVM is not ...
2
votes
1answer
26 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 ...
2
votes
2answers
49 views

How can I more efficiently collect data from users on a vm?

I'm teaching a course this summer. My students' first assignment will be to install a virtual machine that I created (the machine will run Ubuntu). Upon installation they are to run the following ...
2
votes
2answers
92 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} "+"...
2
votes
3answers
40 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ├─...
2
votes
2answers
67 views

find and replace double bracket values

I have a requirement to replace the [[KEY]] in double brackets in one of the html file with VALUE. Key values are available in different files. After replacement, I need to put output in separate file....
2
votes
2answers
61 views

Repeating command line argument

I want to start off by distinguishing that Repeating command with different filenames is not what I am asking. My question is, how do you build a single command with a directory of filenames in it, ...
2
votes
2answers
62 views

How to recover multiple files which has been moved into one?

I was trying to rename (mv) few of my files and ran a wrong loop resulting into renaming all the 10 files into one. Now I can see only one file whereas there should have been ten files. How do I ...
2
votes
1answer
56 views

Why are these nested options in a POSIX shell script being word-split?

I have a script count_args that counts arguments: #!/bin/sh echo $# If I call it with these options, it tells me it gets two arguments: $ ./count_args --options '1 2' 2 But if I construct the ...
2
votes
1answer
31 views

Find all git repos that do not contain any one of .gitignore and .gitattributes

I basically want to find all git repos that have neither a .gitattributes nor a .gitignore file at the root. I used find . -type d '!' -exec test -e "{}/.gitignore" ';' -print to find it but it lists ...
2
votes
2answers
215 views

Is it possible to show rsync output on a single line?

I have a bash script that is rsyncing a large directory and the --progress function is great, but is it possible to show all this output on a single line? ie. as the files transfer, just spit it the -...
2
votes
1answer
50 views

Extract URL from non-formatted text

I've found only examples on extracting substrings from formatted text like HTML files, but in my case I need to output a list of URLs for example: ... https://twitter.com/user1/status/xyza https://...
2
votes
1answer
118 views

How to delete core.* files while the program is running?

I launch my program from .sh file (for simplicity let's say it's content is just ./myprogram). For some unknown reason the program generates large core.* files. What should I add in my .sh file so ...
2
votes
1answer
70 views

Datalogger with PI

I am building a datalogger with raspberry pi. I have used a Shell script in rc.local, I am capturing the Bytes using tcpdump. The Problem am facing is that the log file is getting replaced each and ...
2
votes
2answers
77 views

Find and replace all same files between 2 directories

I want to find all files in dir1 having corresponding same file names in dir2, and replace them with the files from dir2. For example: dir1: first.txt second.txt dir2: third.txt first.txt So I ...
2
votes
1answer
120 views

tr -c '[a-zA-Z]' '\n' not replacing all complement characters

Writting a script I wanted to replace all characters except alpha ([a-zA-Z]) with a line break. By definition, when using -c flag (set complement) tr is supposed to replace all characters that are not ...
2
votes
2answers
597 views

How do I get ~/.bashrc to execute all scripts in my ~/Shell directory using a loop?

I have shell scripts in my ~/Shell directory that I want to be run whenever Bash is started up as my usual user account. So what I have done is added the following to ~/.bashrc: for i in `find ~/...
2
votes
1answer
141 views

Errors with git alias shell command

I'm using bash version 4.1.2(1)-release (x86_64-redhat-linux-gnu) on cygwin with git 1.7.1. I wanted to make an alias for a command that needed to use the input argument twice. Following these ...
2
votes
1answer
126 views

*.desktop nor symlink works (just for this one file) - Linux Mint 17.2 Cinnamon

I have this desktop entry: [Desktop Entry] Name=dummy Type=Application Terminal=false Icon=/home/xyz/Software/Test/ico.png Exec= /home/xyz/Software/Test/start which is supposed to execute file ...
2
votes
1answer
206 views

chmod doesn't work on Mac

I have a very simple question. I cannot make a file executable from the command line on a Mac. This is what I'm typing in terminal cd ./Desktop echo 'say hello' > hello chmod +x hello hello It ...
2
votes
1answer
120 views

echo the created directory name

I'm trying to echo the new directory that I'm creating in the script. BACKUP_DIR=`mkdir /tmp/"$TICKET_NUM"_EAR_BACKUP_"$(date "+%Y%m%d")"` echo $BACKUP_DIR But, the newly created directory is not ...
2
votes
1answer
259 views

System event on AC adapter insert or battery unplugged?

Does Ubuntu 15.04 (or maybe just Linux in general) have any sort of measurable event that fires when a laptop's AC power is disconnected and the unit flips over to battery power? I would like to ...
2
votes
1answer
121 views

How can script execute itself via some exec again?

I'm making script for backing up data from server, it's gonna use ssh and scp many times. My private key is password-protected, but I'm using environment without any ssh agent. I'd like to put ...
2
votes
2answers
571 views

automating CentOS 7 configuration using shell scripts

I notice I spend a lot of time using tutorials to manually configure a CentOS 7 server. How can I convert the manual steps from a tutorial into an automated shell script that can be used to configure ...