Questions tagged [scripting]

Scripting is a form of programming generally characterized by low formality, loose typing, and no requirement for explicit compilation. There are numerous scripting languages, and these are used in a wide variety of scenarios - command-line applications, GUIs, server-side applications, extension modules.

Scripting started out as storing a sequence of commands as a text file, and then feeding the text file into an interpreter or shell.

Early scripting-languages would just read, process, and execute one command at a time. There was no requirement to compile the script into a separate executable file. The source was the program.

Most modern scripting languages feature "interpreters" that perform an internal compilation step, and execute an intermediate code; but this is done automatically, transparently to the developer and user.

Examples of scripting languages are the Unix shells (Bourne and Korn shell, Bash, [t]csh, and zsh), Perl, and the special purpose language, AWK. Other examples include JCL (job control language), RPG, REXX, Windows/DOS BAT files, and MUMPS (used in medical applications). The world's most popular language, JavaScript, is a scripting language.

Over the last ten years, Powershell has become a popular scripting language under Windows, and has been extended to multiple platforms.

Most scripting languages support features such as:

  • dynamic typing
  • direct invocation of external commands
  • direct interaction with the file system
  • basic string processing
  • error control

Scripting languages are traditionally used for common system administration tasks like backups, and software installation and configuration.

Many scripting languages originated as special-purpose tools, and later evolved into powerful general-purpose languages over time. Examples here are Perl and JavaScript.

Over time, the distinction between scripting languages and more "traditional" compiled languages has fuzzed.

For example, interpreters for Python can actually cache its intermediate code, for faster startup times, much like programs written in traditional compiled languages. Conversely, traditional compiled languages are in some ways becoming more script-like, supporting dynamic data typing. The VAR type in the original Visual Basic is an example here, as is the dynamic variable type supported in C# 4.0.

Related tags

16278 questions
3527
votes
20 answers

How do I tell if a regular file does not exist in Bash?

I've used the following script to see if a file exists: #!/bin/bash FILE=$1 if [ -f $FILE ]; then echo "File $FILE exists." else echo "File $FILE does not exist." fi What's the correct syntax to use if I only want to check if the file…
Bill the Lizard
  • 369,957
  • 201
  • 546
  • 842
2301
votes
32 answers

How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN="bla@some.com;john@home.com" Now I would like to split the strings by ; delimiter so that I have: ADDR1="bla@some.com" ADDR2="john@home.com" I don't necessarily need the ADDR1 and ADDR2 variables. If…
stefanB
  • 69,149
  • 26
  • 113
  • 140
2267
votes
16 answers

How to mkdir only if a directory does not already exist?

I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that…
Spike Williams
  • 29,764
  • 13
  • 43
  • 57
2162
votes
37 answers

How do I parse command line arguments in Bash?

Say, I have a script that gets called with this line: ./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile or this one: ./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile What's the accepted way of parsing this such that in each…
Lawrence Johnston
  • 58,608
  • 40
  • 113
  • 181
1576
votes
33 answers

How do I prompt for Yes/No/Cancel input in a Linux shell script?

I want to pause input in a shell script, and prompt the user for choices. The standard Yes, No, or Cancel type question. How do I accomplish this in a typical bash prompt?
Myrddin Emrys
  • 36,888
  • 10
  • 36
  • 47
1227
votes
27 answers

How to count lines in a document?

I have lines like these, and I want to know how many lines I actually have... 09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.00 94.00 09:16:40 AM all 5.00 0.00 0.00 4.00 0.00 0.00 0.00 0.00 …
Alucard
  • 14,592
  • 7
  • 21
  • 22
1144
votes
23 answers

How can I declare and use Boolean variables in a shell script?

I tried to declare a Boolean variable in a shell script using the following syntax: variable=$false variable=$true Is this correct? Also, if I wanted to update that variable would I use the same syntax? Finally, is the following syntax for using…
hassaanm
  • 11,789
  • 4
  • 18
  • 20
822
votes
15 answers

How to run a PowerShell script

How do I run a PowerShell script? I have a script named myscript.ps1 I have all the necessary frameworks installed I set that execution policy thing I have followed the instructions on this MSDN help page and am trying to run it like…
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
780
votes
7 answers

In a Bash script, how can I exit the entire script if a certain condition occurs?

I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests. Is there a way I can do this without wrapping the entire script inside…
samoz
  • 51,592
  • 52
  • 138
  • 190
744
votes
9 answers

How does "cat << EOF" work in bash?

I needed to write a script to enter multi-line input to a program (psql). After a bit of googling, I found the following syntax works: cat << EOF | psql ---params BEGIN; `pg_dump ----something` update table .... statement ...; END; EOF This…
hasen
  • 148,751
  • 62
  • 182
  • 223
667
votes
23 answers

How do I know the script file name in a Bash script?

How can I determine the name of the Bash script file inside the script itself? Like if my script is in file runme.sh, then how would I make it to display "You are running runme.sh" message without hardcoding that?
Ma99uS
  • 9,579
  • 7
  • 29
  • 40
664
votes
12 answers

How do I compare two string variables in an 'if' statement in Bash?

I'm trying to get an if statement to work in Bash (using Ubuntu): #!/bin/bash s1="hi" s2="hi" if ["$s1" == "$s2"] then echo match fi I've tried various forms of the if statement, using [["$s1" == "$s2"]], with and without quotes, using =, ==…
Mr Shoubs
  • 12,813
  • 15
  • 63
  • 103
649
votes
12 answers

How can I set the current working directory to the directory of the script in Bash?

I'm writing a Bash script. I need the current working directory to always be the directory that the script is located in. The default behavior is that the current working directory in the script is that of the shell from which I run it, but I do not…
jameshfisher
  • 26,641
  • 22
  • 94
  • 145
645
votes
16 answers

How can I remove the first line of a text file using bash/sed script?

I need to repeatedly remove the first line from a huge text file using a bash script. Right now I am using sed -i -e "1d" $FILE - but it takes around a minute to do the deletion. Is there a more efficient way to accomplish this?
Brent
  • 14,219
  • 12
  • 38
  • 41
628
votes
15 answers

sudo echo "something" >> /etc/privilegedFile doesn't work

This is a pretty simple question, at least it seems like it should be, about sudo permissions in Linux. There are a lot of times when I just want to append something to /etc/hosts or a similar file but end up not being able to because both > and >>…
David
  • 16,423
  • 8
  • 63
  • 95
1
2 3
99 100