Questions tagged [shell-script]

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

It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.

1460 questions
251
votes
13 answers

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.
nedned
  • 3,342
170
votes
9 answers

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 directory names.
161
votes
3 answers

What does export do in BASH?

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 environment variable. I know that if I don't export a variable I sometimes can't see it…
Chas. Owens
  • 2,682
123
votes
6 answers

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" != "-disCopperBld" -a "$5" != "-disCopperBld" -a "$6" !=…
iman453
  • 1,575
112
votes
6 answers

When must I use #!/bin/bash and when #!/bin/sh?

When is #!/bin/bash more appropriate than #!/bin/sh in a shell script?
Hendré
  • 873
82
votes
5 answers

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 way I can do this? grep for something in a log…
Brian Postow
  • 1,715
82
votes
15 answers

How to execute .sh files on Windows?

When I am trying to execute a .sh file with the command line ./name.sh, I am getting this error: "." is not recognized as an internal or external command, operable or batch file How can I execute .sh files on Windows?
sushant
78
votes
11 answers

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 make that log file rotate? (max size, then switch to a different…
Miral
  • 1,269
72
votes
6 answers

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 resultant out.zip archive has the entire file path in…
jerwood
  • 1,527
62
votes
2 answers

What is the difference between set, env, declare and export when setting a variable in a Linux shell?

What is the difference between set, env, declare and export when setting a variable in a Linux shell, such as bash?
user3872279
  • 1,175
53
votes
3 answers

How to POST file contents using cURL?

I want to do an HTTP POST of the contents (as a string) of a local file located at path/to/my-file.txt to a URL endpoint at http://example.com/. For example, I might want to do the following: Extract the contents of the file my-file.txt as a…
Mowzer
  • 2,509
47
votes
5 answers

How to test if a variable is equal to a number in shell

I have this shell script that isn't working. Input: Server_Name=1 if [ $Server_Name=1 ]; then echo Server Name is 1 else echo Server Name is not 1 fi Output: Server Name is 1 But, if i change Server_Name=2, the output is: Server Name is…
40
votes
2 answers

Unix Script: Wait until a file exists

I need a script that will wait for a (examplefile.txt) to appear in the /tmp directory and once it's found to stop the program, otherwise to sleep the file until it's located So far I have: if [ ! -f /tmp/examplefile.txt ] then
Cidricc
  • 543
40
votes
2 answers

How can I compare a variable to a text string, rather than integer, in an if/else statement?

In the process of writing a shell script, I ran into an issue with the following if/else statement that falls somewhere in the middle of the script: if [ $act -eq "add" ] then read - "add or update: " $comm git commit -m "$comm $file" else …
40
votes
6 answers

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? OS is Windows XP with all the current updates, but…
1
2 3
97 98