A shell script is a script written for the shell, or command line interpreter, of an operating system.

learn more… | top users | synonyms (1)

7
votes
2answers
1k views

Gnu Screen: Execute command on attach

Is there a way to have GNU Screen detect when it is being attached and to execute a shell script that I have whenever it is attached? The reason for this is that I want to keep my display variables ...
0
votes
1answer
572 views

Command not executing inside shell script?

#!/bin/bash value=$(</var/www/sym_monitor/man.txt) if [ "$value" == "true" ]; then ps -ef|grep sym |grep -v grep |awk '{ print $2 }'|sudo xargs kill -9; (cd ...
7
votes
2answers
625 views

How do I delete a file named “-p” from bash?

How do I delete a file named -p in bash? Trying rm "-p" complains that -p is not a valid argument.
5
votes
2answers
2k views

How to extract a complete list of extension types within a directory?

Within a directory, and recursively within it's sub-directories, meaning every directory within a directory is processed, how do I compile a complete list of unique extensions within the directory? ...
1
vote
1answer
709 views

Shell script to fix bad filenames?

I'm IT at my small firm; and, despite my dire warnings, everyone puts files on the server with awful names, including leading & trailing spaces, bad characters (including \ ; / + . < > - ...
1
vote
3answers
229 views

Script for cutting videos based on edit list

I have a bunch of game footage from my soccer team's season and I've assigned each of my teammates one game to watch and write down the time intervals where highlights occur. Now instead of having ...
0
votes
2answers
147 views

How to replace a command with the result of another in linux?

I want to create a command which uses the result of another like this: JNLP_FILE='find . -name viewerApplet.jnlp' cp ${JAR_FILE} ../../sign-jar/$PROFILE/ But I don't know how to execute the find ...
3
votes
2answers
198 views

Fastest way to disable internet (keeping LAN) from command line?

I think the easiest way to deactivate internet (not LAN) is to remove the default gateway, so, assuming LAN is 10.0.2.0/24 and gateway is 10.0.2.1 : In Windows: route delete 0.0.0.0 mask ...
1
vote
2answers
1k views

On OS X, how do I start Cocoa emacs *and* bring it to front?

I wrote a little zsh function to allow me to run emacs from the command-line: function emacs() { /Applications/Emacs.app/Contents/MacOS/Emacs $@ & } This works perfectly, but it seems to ...
0
votes
1answer
645 views

How to remove blank lines in .txt files

I want to change a text file's format, removing all blank lines. How can I do that? (2) 5. The function of the condenser is to: a) vapourise the liquid refrigerant b) change ...
0
votes
1answer
237 views

How to improve this bash shell script for turning hardlinks into symlinks?

This shell script is mostly the work of other people. It has gone through several iterations, and I have tweaked it slightly while also trying to fully understand how it works. I think I understand it ...
0
votes
1answer
1k views

Mac package postinstall script not running

I have created a installer from package maker and scripts I specified scripts directory and postinstall script. When I installs the package it application installs fine but the scripts I specified is ...
21
votes
6answers
51k views

looping through `ls` results in bash shell script

Does any one have a template shell script for doing something with ls for a list of directory names and looping through each one and doing something? I'm planning to do ls -1d */ to get the list of ...
10
votes
2answers
8k views

Programmatically open tab in gnome-terminal, execute command, and have tab stay open

I am trying to write a command that will launch a few terminal tabs, execute something in each tab, and have each tab stay open after the command in finished, so I can look at the output and type more ...
6
votes
2answers
22k views

How to find all soft links (symbolic links) in current directory?

Question relates to shell-scripting in bash. How to check with a script which files within the current directory are soft links? In case I have used the wrong term, when I say soft links, I am ...
14
votes
8answers
45k views

Populating Array in DOS Batch Script

How can I setup an array variable in a DOS batch script? I would like to load it with a list of file names to process. I really would like to keep this as simple as possible. Thank you.
7
votes
2answers
6k views

Passing two arguments to a command using pipes

Usually, we only need to pass one argument: echo abc | cat echo abc | cat some_file - echo abc | cat - some_file Is there a way to pass two arguments? Something like {echo abc , echo xyz} | cat ...
6
votes
4answers
4k views

Run script in OS X 10.6 on network connection. (like /etc/network/if-up.d/)

Is there any way to run a script when a network interface comes up in Mac OS X? I've tried putting a script named ip-up in /etc/ppp but it doesn't seem to fire when I disconnect and reconnect to a ...
6
votes
1answer
19k views

Bash & 'su' script giving an error “standard in must be a tty”

Folks, I'm having an issue with a bash script which runs a particular command as a different user. The background: Running on a Linux box (CentOS), the script is quite simple, it's starting the ...
9
votes
2answers
6k views

Avoid unwanted path in Zip file

I'm making a shell script to package some files. I'm zipping a directory like this: zip -r /Users/me/development/something/out.zip /Users/me/development/something/folder/ The problem is that the ...
5
votes
6answers
292 views

Find all filename.ext1 where no filename.ext2 exists in OS X or the shell

I need to create both TIF and JPG versions of a large set of images. All JPG images already exist, but only a part of the TIF images. Is there an easy way to search a directory to find all JPG files ...
2
votes
2answers
2k views

Renaming multiple files which match UNIX find keyword

I have the following output from find command for finding files containing yyy in name: ./plonetheme/xxx/yyy-logo.png ./plonetheme/xxx/profiles/default/plonetheme.yyy_various.txt ...
6
votes
5answers
7k views

Run a shell script on OS X without having a terminal window appear?

I'm trying to set up a few keyboard shortcuts that open specific iTerm sessions, which I was able to do with BetterTouchTool and a bit of AppleScript magic. The problem is that OS X insists to open a ...
5
votes
6answers
7k views

Starting a linux process in the background

I'm trying to create a script which starts some programs startup.sh knetworkmanager emesene keepassx The problem is that when I run the script, it only starts knetworkmanager. This is because ...
4
votes
2answers
128 views

How can I take the output of a shell script and place it in a file on the command line?

How can I take the output of a shell script and place it in a file on the command line?
3
votes
1answer
904 views

How do you run a shell command/script automatically when entering/cd-ing a directory on Snow Leopard?

Apologies if the answer to this is obvious, but I haven't been able to find one yet (perhaps because I'm searching with the incorrect terminology). I am on a Mac running Snow Leopard and I would like ...
2
votes
3answers
695 views

How to auto source a shell script?

How to make a shell script execute it's commands as source commands without having to use "source scriptname.sh" expression to launch the script? Basically what I want is to type ./scriptname.sh and ...
2
votes
2answers
1k views

Automatically mounting Truecrypt volumes at user login time

I need to mount a Truecrypt volume automatically at user login time. This volume is specific for each user. I'm not sure how to proceed since I'm not extremely familiar with Linux and the various ...
2
votes
3answers
3k views

How to replace part of a text file between markers with another text file?

Say I have a text file like this: # custom content section a b ### BEGIN GENERATED CONTENT c d ### END GENERATED CONTENT I'd like to replace the portion between the GENERATED CONTENT tags with the ...
1
vote
1answer
309 views

Handling whitespaces in the name of a ZFS dataset in a shell script

I'd like to take output from two commands – zpool list zfs list and for each found pool: zpool get all nameofpool and for each found file system: zfs get all nameoffilesystem Background and ...
1
vote
3answers
2k views

MKV to MP4 transcoding script issues

Ok, this one has got me scratching my head - specially as I'm a scripting nOOb, and my *nix expeirence is basic to say the least. Summary Need to identify why the shell script for converting filers ...
1
vote
2answers
838 views

Allow user to execute a shell script without seeing its contents?

I'd like to have an hg hook that sends email using a gmail account. Obviously I don't want anyone to be able read the email-sending script except me or root, since it has a password in, so here's what ...
0
votes
2answers
191 views

Auto backup photos to network drive

My wife's ultrabook is getting full of pictures. I have a NAS that all our pictures are on. What I want to do is store EVERY picture on the NAS (easy) but keep all the photos from the last 12 months ...
5
votes
2answers
1k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
4
votes
4answers
2k views

with a shell script, it is possible to tell when it's run with cron vs run manually?

with a shell script, it is possible to tell when it's run with cron vs run manually? UPDATE: it was asked why I want to know. My cron job will be logging, and i want to be able to log if someone ...
3
votes
2answers
2k views

Multiple parameters to bash script

I need to check for user provided options in my bash script, but the options won't always be provided while calling the script. For example the possible options can be -dontbuild -donttest -dontupdate ...
1
vote
2answers
158 views

How to create multiple folders and name them by reading lines from text file?

I have a plain text file named Export.txt. It contains a list of geographical places, preceeded by a 3 digit number with leading zeros. Example --START OF FILE-- 001 Aberdeen 002 Bellevue 003 Camas ...
1
vote
2answers
666 views

On a linux shell, what is echo $? supposed to do?

I came across a shell script where echo $? was used. What does this mean . How can we use this in a shell script. Are there any references for this.
1
vote
0answers
1k views

Macintosh OS X Logout Script

I am working on a project where I need to implement a logout script on some Macintosh computers. I have read the following Create a logoff script/task for Mac OS X article and found that while it is ...
0
votes
1answer
102 views

Bash delete file when variable = x

I'm creating a bash script which reboots the system at each reboot it adds a new line to a text file, I then read the text file before each reboot. Once the variable holding the number of lines ...
0
votes
1answer
421 views

How to prompt (gui) and use root password on a script?

I would like run a script of mine that need some root privilegies on a gui way. For example, a simple script could be: #!/bin/sh clementine sudo shutdown -h 00:00 The first line opens the ...
0
votes
1answer
1k views

Downloading multiple files with wget and handling parameters

How can I download multiple files using wget? I also want to rename the files. Here are the commands I'm running one by one (copy/paste on terminal): wget -c --load-cookies cookies.txt ...
0
votes
1answer
193 views

Force a backgrounded complex task to fg itself

I will often run a simple monitoring task like the following: (sleep 600 && ls -lh /path/to/files)& Is it possible to have the process de-background itself part way in? For example, to ...
0
votes
2answers
363 views

Get folder with largest number at the end of the name in Linux

On Linux, I have some folders r1, r2, r3, etc. and I want to get the name of the folder with the largest number at the end. How do I get the name?
0
votes
3answers
4k views

make pendrive bootable via command line Ubuntu

I'm trying to burn a .iso image of Ubuntu into a pendrive using command line in Ubuntu but I'm having serious problems. I'm looking for a tool, which I can invoke from a shell script, something like ...