Questions tagged [script]

An automated series of instructions carried out in a specific order, such as a Windows script created to launch a specific program on startup.

2713 questions
638
votes
41 answers

How to execute a command whenever a file changes?

I want a quick and simple way to execute a command whenever a file changes. I want something very simple, something I will leave running on a terminal and close it whenever I'm finished working with that file. Currently, I'm using this: while read;…
Denilson Sá Maia
  • 12,863
  • 12
  • 40
  • 44
477
votes
7 answers

What is the difference between executing a Bash script vs sourcing it?

What is the difference between executing a Bash script like A and sourcing a Bash script like B? A > ./myscript B > source myscript
Scottie T
  • 4,971
  • 3
  • 19
  • 10
239
votes
5 answers

Linux Bash Script, Single Command But Multiple Lines?

I have the following script I wrote by searching Google, and it backs up my Linux system to an archive: #!/bin/bash # init DATE=$(date +20%y%m%d) tar -cvpzf /share/Recovery/Snapshots/$HOSTNAME_$DATE.tar.gz --exclude=/proc --exclude=/lost+found…
Jay LaCroix
  • 2,411
  • 2
  • 13
  • 5
179
votes
8 answers

How to execute a command in screen and detach?

How can I get screen to execute a command and then detach (That is, automatically in a single script without further input beyond initially starting the script)? e.g. I run myscript.sh and it automatically starts a screen session, executes a…
darkfeline
  • 2,072
  • 2
  • 14
  • 15
168
votes
22 answers

Add directory to $PATH if it's not already there

Has anybody written a bash function to add a directory to $PATH only if it's not already there? I typically add to PATH using something like: export PATH=/usr/local/mysql/bin:$PATH If I construct my PATH in .bash_profile, then it's not read unless…
Doug Harris
  • 27,333
  • 17
  • 78
  • 105
115
votes
16 answers

Delete all files from a folder and its sub folders

I want to remove all files from a folder structure, so I'm left with an empty folder structure. Can this be achieved in either batch or VBScript scripting? I have tried a very basic batch command, but this required the user to allow the deletion of…
RobN
  • 1,582
  • 5
  • 15
  • 27
89
votes
10 answers

How can I run an application with command line arguments in Mac OS

Is there any easy way to append command line arguments to an application on a Mac? For example, to run Opera in kiosk mode or to use a different profile in Firefox, I can type $ /Applications/Opera.app/Contents/MacOS/Opera -kioskmode $…
Andrew
  • 2,389
  • 5
  • 27
  • 28
85
votes
11 answers

When to use Bash and when to use Perl/Python/Ruby?

We are doing all our scripting with Bash so far, but I'm starting to feel a bit silly about it. While we can of course do everything we want with Bash (it's quite powerful), I'm starting to wonder if we shouldn't use a proper scripting language (in…
futlib
  • 1,279
  • 2
  • 11
  • 12
80
votes
11 answers

How can I get a script to run every day on Mac OS X?

Cron? Launchd? iCal?? If so, how?
Paul D. Waite
  • 6,434
  • 11
  • 49
  • 72
74
votes
10 answers

Determine if command is recognized in a batch file

I'm writing a bat script in which I invoke a program (such as javac). For simplicity, I want to check if the command exists before I run it. i.e. If the command exists in PATH. For example, if (my_command.exe is a recognized command) then ( …
user46097
  • 771
  • 1
  • 5
  • 6
72
votes
5 answers

Looping Through Subdirectories and Running a Command in Each

I have a set of repositories sorted into directories based on their VCS (Git, Mercurial, SVN). With Subversion I was able to run svn update * in the parent directory and it would loop through each directory and update each repository as expected.…
Bryan Veloso
  • 823
  • 1
  • 7
  • 6
72
votes
2 answers

Does %* in batch file mean all command line arguments?

Does %* in batch file mean all command line arguments?
Matt
  • 6,231
  • 20
  • 57
  • 79
71
votes
6 answers

How do I perform commands in another folder, without repeating the folder path?

Is there a clever way to do copy and move operations or a command to duplicate a file, without having to do a cd, then mv after, at the same folder? For example, I have to run the following: mv /folder1/folder2/folder3/file.txt…
Valter Silva
  • 1,371
  • 7
  • 23
  • 32
69
votes
5 answers

Remotely run script on Unix, get output locally?

I need to run a (Tcl, or whatever) script on a remote Unix machine, from a (local) Windows command shell, and I want the stdout/stderr of the script to show up in the Windows CLI. The exit code would also be useful. Is this possible using ssh…
Cristian Diaconescu
  • 3,632
  • 8
  • 29
  • 34
65
votes
4 answers

How to launch a command on network connection/disconnection?

I have a wifi connection that requires to authenticate using a web form once the wireless link is established. I know how to automate the authentication with a script that uses curl/curlIE. But how can I ask Windows to call my script every time I…
dolmen
  • 1,232
  • 1
  • 11
  • 16
1
2 3
99 100