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

learn more… | top users | synonyms (2)

3
votes
1answer
7k views

Bash command not found error

Why would the following script give following errors : ./check1.sh: line 10: Hi,: command not found ./check1.sh: line 21: syntax error: unexpected end of file check1.sh: #!/bin/bash subj="host ...
3
votes
3answers
446 views

Command for taking a screenshot to a new file

I want to configure a global hotkey to take a new screenshot and save it, say, somewhere inside my home folder. I can take a screenshot with ImageMagick with this command: import screenshot.jpg ...
3
votes
4answers
3k views

How do I select files in a bash script that do not have an extension?

Let's say I have files xinitrc, alphabetsoup, ieat.pie in the current directory. Need a bash script to select only xinitrc and alphabetsoup.
3
votes
3answers
184 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
3
votes
5answers
657 views

changing pattern of a text file

A text file has contents something like chair table pen desk Now i want it to be changed and stored in a variable say var as below ('chair','chair'),('table','table'),('pen','pen'),('desk','desk') ...
3
votes
2answers
798 views

Move with possible rename

Is it possible to construct a command that will move the file to another directory and if the same file is already there, generate some random string that is not in the name of some file in the ...
3
votes
2answers
3k views

Get path of current script when executed through a symlink

I have a utility consisting of a couple directories with some bash scripts and supporting files that will be deployed to several machines possibly in a different directory on each machine. The ...
3
votes
2answers
266 views

pulling strings out of mixed file of strings and binary

I'm trying to get my nokia backup file into an acceptable vcard format. It has valid vcard strings that appear in between binary data. For example: !@#JUNKCHARACTERS!@#!@BEGIN:VCARD VERSION:2.1 ...
3
votes
3answers
13k views

How can I call other shell script like a subroutine?

How do I call an other shell script and wait for its completion? I want to pass input arguments and receive returning result code. And continue running rest of codes.
3
votes
7answers
1k views

How to write repeated free-form strings to a file, as fast as 'dd'?

dd can write repeating \0 bytes to a file very fast, but it can't write repeating arbitary strings. Is there a bash-shell method to write repeating arbitary strings equally as fast as 'dd' (including ...
3
votes
2answers
227 views

Shell script wrapper to prevent running command with no arguments?

There is program I use, say xyz, that has undesirable effects if I run the command bare with no arguments. So I'd like to prevent myself from accidentally running the xyz command with no arguments ...
3
votes
3answers
105 views

Count nul delimited items in file

I have a shell script which uses find -print0 to save a list of files to be processed into a temporary file. As part of the logging I'd like to output the number of files found, and so I need a way ...
3
votes
2answers
110 views

get result text from CLI command

I'm writing a bash script and I need to capture the text resulting from the output of the rsync command, for instance, the following command: rsync -av "$FOLDER1" "$FOLDER2" prints: ... sent ...
3
votes
1answer
347 views

How do I fill my password automatically from .bash_profile when running command as sudo?

I know I could just put something like sudo mypassword in my .bash_profile, but I don't want to run every command as root. I want password to autofill under following circumstances: only the ...
3
votes
2answers
144 views

Find files in directory with paired names

I'm running tests of a variable-size-and-contents test set. Data files are added and removed frequently. I'm looking for an automated way of gathering a file list. All files are in subdirectories of ...
3
votes
3answers
597 views

AWK: Passing shell variables to awk

I am trying to pass a variable number of arguments from the shell script to a pattern recognition subset of a table. Here is my attempt so far: The file 'infile': ID,GROUP 1,GROUP2 ...
3
votes
1answer
1k views

Why does the filename contains question marks when I run a script on my remote machine?

I have a tiny script that simply fetches the current date, runs a PHP script and redirect the output (and errors) to a filename containing the current date. DATE=$(date +"%Y%m%d") ...
3
votes
1answer
711 views

What's the difference between “==” and “=~”?

Given a string and a hash returned by openssl, why using == doesn't match them correctly but =~ does? Background question: How can I force a script to use more resources?
3
votes
2answers
324 views

Moving large numbers of files and directories to a different directory

I'm trying to move the following move a large number of files that exist in the following structure to a /mnt/originals but I need to maintain the structure at the same time. I know cp would be a ...
3
votes
4answers
786 views

Replace all newlines to space except the last

How can I replace all newlines with space except the last newline. I can replace all newline to space using tr but how I can do it with some exceptions?
3
votes
2answers
203 views

How to make /etc/init.d script act like it's launched under X?

I'm trying to track down some quirkiness with a Java application that misbehaves when launched via a startup script in /etc/init.d , but runs fine when you open a GUI terminal window and run it ...
3
votes
2answers
867 views

How to find frequency of occurrences of strings contained in a file?

I have a file that contains a list of URLs of the form EDIT http://www.google.com/absd/siidfs/kfd837382$%^$&, www.google.com, google.com yahoo.com/list/page/jhfjkshdjf... I ...
3
votes
4answers
1k views

Align text to center with padding on both sides

Is there an easy way to align text to the center with padding on both sides, with the column width being the longest line from the input? For example, this: aaa bbbb c ddddd ee will turn into this ...
3
votes
3answers
1k views

How to convert all .wav files in subdirectories to .aac using neroAacEnc?

I have a collection of music in .wav format, and would like to convert it to .aac/.mp4 using neroAacEnc. How do I do this? I am using Arch Linux x86_64 and Xterm.
3
votes
1answer
68 views

Using a ; or && with $@

I'm trying to do something with a cron wrapper and my cron looks something like * * * * * root /usr/bin/wrapper cd /tmp/ && ls Then wrapper looks like #!/bin/bash "$@" When I run it I ...
3
votes
6answers
211 views

Extracting help message from script itself

I want that my help message be extracted from the script itself. #!/bin/bash # # foo - do things # Author: John Doe <jhon@doe> # ---------------------------------------------- # SYNOPSIS # ...
3
votes
2answers
5k views

How can I trim the carriage return from text that is being piped in bash?

I'm using this command to get my last typed command: history | cut -c 8- | tail -n 2 | head -n 1 It works very well in bash, removing the line numbers, but there is one problem I have with it, (er, ...
3
votes
2answers
7k views

Automate file transfer from Windows to Unix

I have the following situation: users update csv/txt files on daily basis on Windows. I use those flat files as input for my Oracle scripts which is on Unix. I need help on script/method of ...
3
votes
1answer
116 views

'find' across directories named …/dirnameXX/… with XX variable

I am executing this command to find certain files in specific directory: find ./rgs/test/maesXX/master/stdlist -name \*.extract \ -mtime +30 \! -size 0 -exec ls -lrt {} \; where XX could be ...
3
votes
3answers
3k views

What are the significant differences between different shells? [duplicate]

Possible Duplicate: What are the fundamental differences between the mainstream *NIX shells? If I write a shell script in bash, will it run in ksh as well? if not, what are the ...
3
votes
4answers
5k views

Establish openvpn tunnel in bash script

I'm trying to write a script which will establish an openvpn tunnel when the computer boots up. The main problem lies in inputting the pkcs12 password. I realise it's very bad practice to have a ...
3
votes
4answers
595 views

shell scripts that respond to console output

Disclaimer:: I am not an active shell scripter How does one create a script that responds to console output? For instance, I'm trying to setup a cron that periodically svnsync 's changes to my ...
3
votes
2answers
103 views

How to add new lines from another file with sed

I'm trying to find the sed command so that I can put filename into filename1. These are my two separate files. INPUT filename has: Cindy 11 22 54 Chester 48 12 84 INPUT filename1 has: Name ...
3
votes
3answers
332 views

Better way to run single for loop instead of two for loops

This works but the way I did this is kind of silly. Is there a better way to do this? for e in $(ipcs | awk '{print $2}'); do [[ "$e" = "Semaphore" ]] && break echo $e ipcrm shm ...
3
votes
3answers
163 views

Having an issue searching for a string in a file

I have tried to use a 'case' loop but it doesn't work for a reason unknown to me. This is my script for the case loop. echo "Do you wish to search again? [y/n]" read INPUT_STRING2 case ...
3
votes
2answers
657 views

Unable to pass a bash variable as a python argument in bash

For some reason I cannot pass the bash variable $FOLDER as a python argument on the following code. The python script downloads some files from amazon s3. Bash script: #!/bin/bash FOLDER=$(./aws get ...
3
votes
3answers
226 views

Is there some way I can start a (repeating) ping while the network is unreachable?

My ping command (on Debian 6 or 7) will repeatedly attempt to ping a server even while the network is down, if the network was up when it was started. Is there some way to start ping while the network ...
3
votes
3answers
1k views

'is a directory' error when trying to pass directory name into function

Note: I am a newbie to bash scripting In my bash script, I use find to get the folder names by wildcard: for i in $(find ${directory} -mindepth 1 -type d -name ${wildcard}); do stuff=doStuff ${i} ...
3
votes
2answers
948 views

Interactively concatenate video files

Problem : How to concatenate (join) multiple MP4 video files into one file interactively? There are a lot of programs that do this for two files from the command line. For instance : ffmpeg, ...
3
votes
2answers
247 views

Sorting Photos using shell script

The majority of my photo files have the following naming convention / format IMG_20131204_120000.JPG, showing date and time the photo was taken (iPhone/Apple naming convention). However, not all my ...
3
votes
2answers
148 views

Running commands after event based outputs

there are commands like iwevent or tcpdump -n src host x.x.x.x that send to the stdout some lines when something happens. Is there any form of running some command inmmediatly after a ...
3
votes
3answers
719 views

Rename the last 8 characters in filename

I am receiving video files with different names but the final 8 characters of all are numbers (also different every time). This is the pattern of the file name: custom text 00030402.avi I have to ...
3
votes
2answers
2k views

How to safely reverse dns lookup on ip in a shell script

I'm trying to find out how to take in a hostname and pop out an ip address (reverse dns lookup). I came up with this but I'm not too sure it's safe across different linux distros: nslookup $ip|grep ...
3
votes
3answers
630 views

Quote a variable in shell script “if” statement

e.g. if [ "$FOO" = "true" ]; then vs if [ $FOO = "true" ]; then What is the different? Seems both of two statements also works.
3
votes
4answers
275 views

Show video files with its size

I need all the .mp4 files' dimensions to be printed with the file name. For example: 1_VIDEO.mp4 1204x680
3
votes
3answers
172 views

Delete files except n files with the “bigger” name?

I want to create a shell script that deletes old release files except last n files. In other words, only mantain last n releases when I deploy a new release. File names have this format: ...
3
votes
2answers
643 views

How to run "find -exec <script> {}\;

I have a script that changes the properties of the files for a folder. Here is the example tree: dir 1 --file 1 --file 2 --file 3 dir 2 --file 1 --file 2 dir 3 --file 1 ...
3
votes
2answers
11k views

In a bash script, using the conditional “or” in an “if” statement

This question is a sequel of sorts to my earlier question. The users on this site kindly helped me determine how to write a bash for loop that iterates over string values. For example, suppose that ...
3
votes
3answers
3k views

Shell Script to Execute Shell Script to All Subdirectories

I am making a script to simplify my daily tasks. Everyday, I have to grep for a few things inside a company server. It was okay, however, now, they have segregated each object into sub directories. I ...
3
votes
2answers
1k views

How to solve sudo: unable to execute /bin/ls: Argument list too long

When I run this command from php sudo -u db2inst1 ls -t /var/lib/edumate/bdrs/*/*/daily/*NODE* | sort -r I receive sudo: unable to execute /bin/ls: Argument list too long ls lists all daily backup ...