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

learn more… | top users | synonyms (1)

80
votes
7answers
88k views

Batch converting PNG to JPG in linux

Does anyone know a good way to batch-convert a bunch of PNGs into JPGs in linux? (I'm using Ubuntu). A png2jpg binary that I could just drop into a shell script would be ideal.
7
votes
2answers
2k 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 ...
3
votes
1answer
2k views

Linux command-line: Fastest way to disable internet (keeping LAN)?

Split question: this other one here is for Windows. Linux: Fastest way to disable internet (keeping LAN) from command line? I think the easiest way to deactivate internet (not LAN) in Linux is ...
0
votes
1answer
1k 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 ...
17
votes
11answers
72k 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.
17
votes
2answers
13k 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 ...
12
votes
3answers
5k 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? ...
11
votes
5answers
17k 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 ...
14
votes
4answers
9k views

How do you escape apostrophe in single quoted string in bash?

I don't understand how bash evaluates escaping of apostrophe characters in single quoted strings. Here is an example: $ echo ''\''Hello World'\''' 'Hello World' # works $ echo '\'Hello World\'' ...
7
votes
2answers
817 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.
1
vote
1answer
1k 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 \ ; / + . < > - ...
0
votes
2answers
178 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 ...
1
vote
1answer
1k views

Windows command-line: Fastest way to disable internet (keeping LAN)?

Split question: this other one here is for Linux. I think the easiest way to deactivate internet (not LAN) in Windows command-line is to remove the default gateway, so, assuming LAN is ...
1
vote
2answers
1k 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 ...
1
vote
3answers
330 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 ...
10
votes
2answers
3k 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 ...
1
vote
1answer
71 views

Bash quotes unescaped on command substitution

Can someone explain me why this is working (listing the contents of a directory that has a whitespace in its name): ret="$(ls "my dir")" Shouldn't it rather be interpreted as: ret="$(ls " my dir ...
1
vote
2answers
2k 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
273 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
2k 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 ...
-2
votes
2answers
3k views

Calculate % difference and file sizes between two files

We have two zip files and would like to compare them. We're also interested in calculating the percentage difference between them and the file size. Is there a tool that can do this quickly?
37
votes
7answers
99k 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 ...
11
votes
2answers
11k 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 ...
11
votes
3answers
12k 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 ...
8
votes
2answers
27k 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 ...
9
votes
7answers
63k views

ssh and shell through ssh : how to exit?

I'm launching a distant script through SSH like this: ssh user@ipaddress '~/my_script.sh' Everything is going fine but once the script is finished, the connection is not closed. I Have to press ...
8
votes
5answers
7k 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 ...
30
votes
11answers
263k views

How to execute .sh file on Windows?

When I am trying to execute a file(name.sh) in the command line by the command ./name.sh , I am getting the error that: "." is not recognized as an internal or external command, operable or ...
8
votes
4answers
5k 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 ...
11
votes
4answers
1k views

Who deals with the star * in echo *

Who deals (interprets) the * in echo * Does the echo see the star or the shell take care about it and return a list of filename .. What about cp temp temp*
7
votes
2answers
4k views

How do I close a window from an application, passing the file name?

I’m trying to produce an Applescript-based shell command that tells the Preview application from Mac OS X to close a particular window. #!/bin/sh osascript <<EOF tell application "Preview" ...
6
votes
1answer
24k 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 ...
5
votes
6answers
506 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 ...
4
votes
1answer
1k views

Shell scripting: Way to parse parameters from command line

myscript [-a a-arg] [-c c-arg] [-b] [-e] somedirectory Given that I want my shell script be invoked at the command line using the above parameters - where [these brackets] denote that they are ...
3
votes
3answers
1k 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
4k 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 ...
1
vote
2answers
985 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 ...
8
votes
6answers
14k 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
1answer
1k 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 ...
4
votes
2answers
142 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?
2
votes
1answer
153 views

What this command :(){ :|: & };: does? [duplicate]

What does this shell command do in Linux :(){ :|: & };: How can it be used in Denial of Service attacks?
2
votes
2answers
2k 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 ...
1
vote
1answer
602 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 ...
0
votes
2answers
318 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
4answers
3k 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
8k 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 ...
3
votes
2answers
691 views

Shell script that starts a process, starts another process, then kills the first process

Let's imagine I have a client and a server on the same machine, and I'd like to script some interaction between them. I would really like a shell script to - Start server Put server in the ...
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 ...
2
votes
1answer
54 views

Is this a bash-specific method of calling a script: VARIABLE=value bash somescript

I have worked all my life in HPUX/ksh shell, so bash these days seems to be throwing new ways of doing many things (many of which don't seem to be POSIX compliant - for example 'mkdir -p ...