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.

1433 questions
239
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,212
  • 3
  • 18
  • 12
157
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.
Daniel A. White
  • 4,038
  • 2
  • 26
  • 30
138
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,412
  • 3
  • 20
  • 23
109
votes
5 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,435
  • 2
  • 13
  • 13
108
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é
  • 833
  • 3
  • 8
  • 13
80
votes
15 answers

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 batch file please help me execute the .sh file
sushant
74
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,189
  • 1
  • 9
  • 12
70
votes
4 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,467
  • 2
  • 12
  • 16
65
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…
Brian Postow
  • 1,555
  • 2
  • 15
  • 22
53
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,085
  • 2
  • 9
  • 18
42
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,179
  • 3
  • 18
  • 28
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 …
tony_perkis666
  • 547
  • 1
  • 5
  • 7
39
votes
5 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…
blunders
  • 877
  • 4
  • 15
  • 23
37
votes
2 answers

What is wrong with “echo $(stuff)” or “echo `stuff`”?

I used one of the following echo $(stuff) echo `stuff` (where stuff is e.g. pwd or date or something more complicated). Then I was told this syntax is wrong, bad practice, non-elegant, excessive, redundant, overly complicated, cargo cult…
Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
36
votes
12 answers

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.
Jim Fell
  • 5,836
  • 16
  • 55
  • 76
1
2 3
95 96