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

learn more… | top users | synonyms (2)

3
votes
3answers
1k views

How to move the first x files

I have this huge folder with thousands of unordered files. Is it feasible to move the first 5000s to a subfolder via the mv command? For now I move files with mv *some_pattern* ./subfolder1/ ...
1
vote
2answers
201 views

Run a Shell script and read the output in a variable and run another script based on output

I am a novice to Linux system. My requirement is to run a Linux status script which echos a message (message is either "App is running" or "App is not running"). If the message is "App is running" ...
1
vote
2answers
131 views

Copying and renaming files to a single directory by a single shell script

I have multiple files with an example of how they look like shown below. -rw-r--r-- 1 my_user users 12 Dec 13 09:56 Example_30_001_20130913175000.DAT -rw-r--r-- 1 my_user ...
3
votes
1answer
195 views

Is there a way to embed a GPG public key in a script without adding it to the keyring?

I have a script that basically needs to do the following: #!/bin/bash GPG_PUBLIC_KEY=<<EOF -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.12 (GNU/Linux) ... -----END PGP PUBLIC KEY ...
13
votes
1answer
2k views

GNU parallel vs & (I mean background) vs xargs -P

I'm confused about the difference or advantage (if any) of running a set of tasks in a .sh script using GNU parallel E.g. Ole Tange's answer: parallel ./pngout -s0 {} R{} ::: *.png rather than say ...
3
votes
3answers
535 views

Grep command in shell script

I've been writing a shell script which should make grep command outputs for further use. However when I pass a variable containing ~/.../multiple_dir/* to grep as input I get empty output file. ...
2
votes
2answers
694 views

Passing options to subcommands in bash

I'm scripting a sequence of commands I used to enter by hand. The rough outline goes something like this $ echo ${FILENAME_ARGS} | some | big | pipeline | sort -options | etc >temp $ gs ...
1
vote
1answer
83 views

TPS Based Shell Script

I am writing a shell script to test my soap web service's load handling. But I am not sure how to simulate the TPS value. Can you help me to find a way to handle that ?
4
votes
2answers
157 views

Remove duplicates from basenames in two files

I have two long lists of filenames, and I want to merge these two by excluding duplicated filenames in the sense of basename. For example, I have something like ../data_folderA/file_1 ...
0
votes
1answer
156 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
2
votes
1answer
167 views

Are double “if” statements allowed in shell scripts

In C language we can use if(a==b&&a==c) we can make a double and statement is that possible in unix, to be specific in a shell script?
5
votes
4answers
8k views

How can I suppress output from grep, so that it only returns the exit status?

I have the grep command. I'm searching for a keyword from a file, but I don't want to display the match. I just want to know the exit status of the grep.
2
votes
2answers
2k views

Catch “command not found” from shell script

I have a shell script echo "Type your command" read command echo "You typed $command" $command so it's simple it runs a command.My question is if the input is wrong suppose lw the terminal says ...
3
votes
0answers
121 views

Understanding line numbers reported when using eval

Okay, so I'm stuck working with a shell script that needs to use eval (I know, I know, ultimate evil etc…) however I'm having difficulty debugging some of the line numbers being thrown out by errors. ...
0
votes
3answers
6k views

Shell script read separately columns from file

When we have file which is a kind of list like : Mary 34 George 45 John 56 Josh 29 using the awk command $1 refers to the first column and $2 to the second column.But once we write a shell script ...
-1
votes
1answer
96 views

Checking if folder exist using case/switch

Is it possible to use case to check if folders exist? I have these folders. I need to check if they exist then do something afterwards, I have 5 folders I need to check, and if it does exist, I ...
1
vote
0answers
47 views

List Mails by subject

I'm writing a script to send mails from a mailbox on a remote server and a script to check if the mails are received at another remote server. For this I have configured mutt. What I now need is to ...
1
vote
1answer
1k views

How to use command line arguments in a shell script

I have a shell script and when invoking it ./test it asks for an input.I 've seen a quicker way just by writing at once ./test myInput ,how is that achievable?
-1
votes
2answers
528 views

How to manipulate output from commands with shell scripts [closed]

Simple question, having a ls -l command it makes a list on the command prompt and if we want to manipulate it we pipeline it with awk command, for instance if we want to to show specific files. Is ...
2
votes
2answers
1k views

Remove scientific notation bash script

When I convert MB to GB I'm getting below output. I want this output in normal format. When I use bc I'm getting an error. The text file contains nearly 100 such lines like this. I want to print this ...
2
votes
1answer
151 views

How to avoid sending EOF from a script parsing requests from and sending answers to netcat

I made a simple server using netcat and backpipe: mkfifo backpipe nc -l 8080 < backpipe | parseRequests.sh > backpipe The contents of "parseRequests.sh" is just: #!/bin/sh if [ "$1" = "1+1" ...
0
votes
2answers
93 views

mount -a locks up my script if any of many remote drives are offline

I've written a backup script which backs up multiple windows servers by mapping those server's hard drives to the linux file system at a particular mount points. At the beginning of the script, I ...
3
votes
1answer
646 views

How do I tell if a program is printing to stderr or stdout in the terminal?

NOTE: a newline appears but od -c doesn't display it. My music player's status command (quodlibet --status | od -c) has three states, and I'm trying to write a conditional based on that output. The ...
1
vote
3answers
104 views

Automating pipes?

I find myself using basically the same line over and over again: cat file | command1 | command2 | command3 > file Is there a way I can put all these pipes into one script, so I can just run ...
7
votes
2answers
932 views

Piping data to a process's stdin without causing EOF afterward

I have an executable that starts a user-interactive shell. I would like to, upon launch of the shell, inject a few commands first, then allow the user to have their interactive session. I can do this ...
1
vote
3answers
2k views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
12
votes
3answers
549 views

How do I wait on a program started in another shell

I have a program that does a large a amount of work (takes about 4-5 hours) that gets started by cron when all the data it works with becomes available. Sometimes, when I am waiting for it to finish, ...
3
votes
2answers
316 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
1answer
235 views

Count number of sessions and email as a body

I want to create a script to achieve followings : 1.login to Essbase MaxL essmsh -l admin password on localhost; 2.Count the number of lines in the output of command display session all; display ...
0
votes
1answer
4k views

How to Create a Unix Executable File [closed]

Is it possible to create what the Mac Finder specifies as a "Unix Executable File" and run it in Terminal like any other command instead of creating a .sh or .command file? If so how and where can I ...
2
votes
1answer
1k views

Change executable reference for app icon in in GNOME 3 launcher

I've created a custom script to launch VirtualBox that replaced the original script in ¸/usr/bin/¸. So running VirtualBox in a terminal launches my script. However, pressing super key and type ...
1
vote
0answers
258 views

Shell script to backup VMware VM's, exporting each VM to a list then asking user intput

What I'm Trying To Accomplish: Get list of Virtual Machines ".vmx" file and place in variables Give the user and choice of which VM to backup Use "ovftool" to produce an export of the chosen VM to ...
1
vote
1answer
94 views

How to resolve a hostname via nsswitch?

I want to test in a script whether a hostname resolves to something other than 127.0.0.1 as a pre-flight test for an install script. The tools I know (dig, nslookup) specifically query DNS. In my ...
3
votes
1answer
152 views

Find directories with a certain name

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be ...
3
votes
3answers
183 views

Why is my condition always false?

I tried to write a script which creates a user. First it needs to check if: root is running if user maybe already exists I Also tried to set the password equal to the username which was typed ...
8
votes
3answers
363 views

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
2
votes
2answers
90 views

OS X: how to keep the computer from sleeping during a http connection

An application I use downloads data from a specific server, and I need it to sleep after the download has finished and the socket is closed. However downloads take place at random days, the app that ...
1
vote
2answers
344 views

How to invoke a shell built-in explicitly?

I want to customize the functionality of cd command as per my needs. I define following function - function cd () { cd "$@" && pushd "$@"; } The intent of this function is to automatically ...
7
votes
3answers
33k views

How to rename multiple files in single command or script in Unix? [duplicate]

I have the below list of files aro_tty-mIF-45875564pmo_opt aro_tty-mIF-45875664pmo_opt aro_tty-mIF-45875964pmo_opt aro_tty-mIF-45875514pmo_opt aro_tty-mIF-45875524pmo_opt that I need to rename to ...
3
votes
1answer
119 views

script to remember dir and always cd to it instead of the root dir

How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ? #!/bin/bash setdir() { cd $1 # remember the directory ...
6
votes
3answers
1k views

Using `kill -s 0 $pid` vs `[[ -e /proc/$pid ]]` to detect if PID is running

One of the idioms often used to check if process is running is to use kill -s 0 $pid. My question is, does it have any upsides over using [[ -e /proc/$pid ]] construct? The script I'm writing is ...
4
votes
2answers
573 views

Create sub-directories and organize files by date from file name

I have been using the following script to organize my photos into "Date' Directories: for x in *.JPG; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" "$d/" done This script works ...
1
vote
1answer
60 views

auto-delete fluxbox menu entries

I want to delete fluxbox menu commands that are in the form of - [exec] (foobar) {/usr/lib/xscreensaver/foobar -root} and there are 50+ commands to be deleted. But, how do I do it please? I need a ...
2
votes
1answer
211 views

Can't echo or create a symbolic link to a file with special characters in its name inside bash script

I'm trying to create a symbolic link to files with the following naming convention: .$abc$namehere.zip;1 As can be seen, it has the following special characters in it: . $ ; In my bash script I ...
5
votes
2answers
1k views

Get the PID of file creation

I am writing a bash script that creates 5 files with the extension ".P" and write a line of "something" into them. "P" represents a number and it's the PID of the process that creates the file. How ...
11
votes
2answers
2k views

find and remove duplicates in a directory

I have a directory with multiple img files and some of them are identical but they all have different names. I need to remove duplicates but with no external tools only with a bash script. I'm a ...
-3
votes
1answer
33 views

Need help with this script [closed]

I'm supposed to write a bash script that has as an argument a path to a directory which contains a file named checking.txt. It needs to return the following exit codes: 4, if the directory doesn't ...
1
vote
3answers
327 views

Creating a file counter that includes hidden files

As part of a programming assignment I need to create a piece of code that will count the number of files and directories (including hidden) recursively. I'm not allowed to use the commands -R, find or ...
0
votes
0answers
114 views

Shell Script : Check for all the source files in different paths

This is the naming convention of the file. <yearmonthdate>_<sourcesystem>_<totalnoofpartsof file>_<subject area>_<part number>.dat (or .dat.gz) First part is Date, ...
0
votes
1answer
513 views

Meaning of different options used while running a shell script

I was reading a shell script and I found the below command there. I tried searching on Google thinking attach, force and delete are the options used while running a script. But failed to find ...