How to learn to write scripts. How to write scripts for Windows? How does it all work


In this article:

  • Placing PHP on an HTML Page
  • Comments in scripts
  • Text display
  • Variables and Constants in PHP
  • Assignment operator
  • About data types

Any text editor (for example Notepad++) is suitable for writing code in PHP.

Placing PHP on an HTML Page

PHP script code can be placed directly on the HTML page. To see how this is done, let's look at the following simple example:

This is a regular HTML document

At first glance, the example resembles a regular HTML file. The only innovation here is the design.

Everything between is interpreted as PHP code. Here we also see an example of the use of the echo command, one of the most important, frequently used commands when programming in this language. The echo command is used when you need to write something in the current document. So our small PHP program prints the phrase “And this is PHP” in an HTML document. Everything that is outside the PHP processor is transferred without modification directly to the dynamic web page.

Instead of a special tag, the following tags can also be used:

PHP code

Our first scenario

The texts of scripts (php programs) must be stored in files with the php extension.

PHP code consists of individual statements, each of which ends with a semicolon (the absence of one will cause an error message).

The first PHP script (index.php file) will be quite simple, but it will already demonstrate the combined use of HTML and PHP.

First example

The PHP program consists of two assignment statements, defining the value of a constant, and printing text and the current date to the browser window using the echo command.

This text can be typed in any text editor, for example, NotePad++, and saved under the name index.php. You must make sure that the file is saved as a php file, otherwise it will not be processed correctly by PHP.

In case of local work, you need to copy the index.php file to the documents directory of the web server. For Denver this is home/localhost/www (unless otherwise specified in the settings). After which you can proceed directly to running the script.

To run the index.php script, open a web browser and then enter the full path to this script in the address bar. In case of local installation, the address will be like this:

If everything is done correctly, we will see on the screen:

Styles.css file (style sheet):

/* Styles for displaying page content */ * ( margin: 0; padding: 0; ) body ( font-family: Verdana, Arial, sans-serif; color: #14556b; background-color: #f2f2f2; margin: 20px; ) h3, p ( margin: 6px 0; /* Heading and paragraph margins */ )

Directly from the browser we can view the code of this page generated by the web server:

Thus, the name of the variable is replaced by its value, which is placed to the same place, where the name of this variable was in the program.

So, PHP files are usually a mixture of HTML, CSS and PHP. In this case, the PHP code is always contained within the . The web server sends the HTML code to the browser without modification. The PHP code is executed, and if it generates tags and any text to display, that text is inserted to that place, where the PHP code was located. The browser interprets the page's HTML tags and displays the result on the screen.

PHP code can be located in any location and be included multiple times in the script text. It can also be used to generate HTML tags, as can be seen from our example.

Comments in scripts

There are three types of comments in PHP. The first allows comments to be placed on multiple lines, starting with /* (written without a space) and ending with */, for example:

It should be kept in mind that Nested comments cannot be written.

Multiline comments can be useful where you need to insert a significant amount of text. Additionally, a common technique when debugging a program is to comment part of the code (to prevent it from executing).

The other two types of comments begin with the // or # symbol and continue only to the end of the line in which they are written. This type of comment is convenient because it can be placed to the right of statements, for example:

Very often a comment is added at the beginning of a script to give a brief overview of it and indicate what functions it performs. For example:

Text display

The echo operator, which is designed to display arbitrary text on a web page, is perhaps the most commonly used PHP operator. In the simplest case, after echo you should place one line in quotes. Text can be enclosed in double quotes or single quotes ( apostrophes). To display numbers, quotes are optional, for example:

In general, after echo you can write several lines of output, separated by commas.

If necessary, a long line can be placed on several lines in the script text, for example:

Individual strings can be concatenated using the concatenation operator "." -- dot. The result is a single string that is passed to the echo operator. For example:

which is equivalent

To display a quotation mark, precede it with a backslash, for example:

Note. If you are outputting a single line of text, you can use the print function instead of the echo statement. In this case there is no difference between echo and print. However, in echo we can append other lines to the first line, separated by commas.

Displaying Large Text

When using echo to display a large amount of text, it can be written like this: first we put the characters .

Variables, assignment operator

As in any programming language, variables are designed to store data. In PHP, variable names always begin with a dollar sign $, followed by a letter or underscore, and can be followed by any number of letters, numbers, or underscores. Keep in mind that variable names have different uppercase and lowercase letters. For example, $var and $Var are different variables.

After creation variable (as a result of assigning a value to it), access to this variable is possible anywhere in the script. In this case, the same variable can contain values ​​of different types throughout the program.

The variable exists as long as the program is executed.

To assign a value to a variable in PHP, use assignment operator, denoted by the equal sign =. The following are examples of assignment operators:

$ternperature = 24;

$number_of_earths = 1;

$pi = 3.1415926535;

$message = “Good morning!”;

Please note that some variables are assigned numbers, while others are assigned strings.

Exercise . Print all the values ​​of these variables to the browser: (1) each value on a new line; (2) –– all values ​​–– in one line.

Constants

Sometimes it is not necessary to change the specified value in the program once. For this purpose they are used constants- their values ​​do not change during script execution.

To describe a constant, use the define function, which is passed the name of the constant and its value. There is a convention that constant names are always written in upper case (capital letters), for example:

define (“PI”, 3.1415926535);

Please note that when defining a constant, it is not preceded by a dollar sign. Trying to change the value of a constant using the assignment operator will result in an error.

Constants cannot be given names that are PHP function words (since the constant name is not preceded by a dollar sign).

Reserved (service) words of RHP:

and array as break default
die do echo endif endswitch
endwhile global if include print
require eval lnclude_onc e require_once return
case withfunction class const continue
declare else elseif empty enddeclare
endfor endforeach exception exit extends
for foreach function isset list
new old_function or php_user_filter static
switch unset use while xor

The PHP language defines many built-in constants that can be used in scripts. These constants start with two underscores and end with two underscores. For example:

__CLASS__ __FILE__ __FUNCTION__ __LINE__ __METHOD__

Aborting script execution

The most common way to stop script execution is exit(). Another useful function is die (“Message”), which also allows you to display an error message. This allows you to tell the user why the script failed.

Destroying a variable

Sometimes you need to forcefully destroy a variable. The unset() function is designed for this.

If we try to echo “$variable” after calling the unset function, we will get an error message—the $variable variable will no longer exist.

You can destroy multiple variables at once:

unset($variable, $name);

You can skip the following text on first reading

Data types

In PHP, the type of a variable is determined automatically when a variable is created based on its value. However, you should be aware of the types of data that may be used. There are eight of them in total:

  • Boolean type, contains the values ​​TRUE or FALSE.
  • Integer.
  • Real number.
  • Text of arbitrary length.
  • Array.
  • An object.
  • Resource (for example, file).
  • NULL The value is NULL.

For example:

$variable = TRUE;

In this case, the type of the variable is determined unambiguously. The difficulty begins when mixing different types of data in one expression, for example, when adding an integer and a string that represents a number. Below are some examples of such expressions:

To prevent potential problems, you should not mix different types of data. Even so, PHP performs implicit type conversion. If you need to perform an explicit type conversion, then the required type must be indicated to the left of the variable name in parentheses. Here are some examples of explicit type conversion:

$int_variable = (integer) $variable;

$float_variable = (float) $variable;

$string_jyariable = (string) $variable;

When converted to boolean, the following values ​​are converted to FALSE.

  • Integer 0.
  • Real number 0.0.
  • Empty string and string “0”.
  • An array with zero elements.
  • An object that has no properties.
  • Special type NULL.

When converting to an integer value type, other types are converted as follows:

  • The logical FALSE is converted to the integer 0, the logical TRUE is converted to the integer 1.
  • Real numbers are rounded down. When converting to a real number, the conversion to an integer value is first performed.

It is also possible to convert string values ​​to numeric data types, but there are some caveats.

Any other values, including all resources, are converted to TRUE.

Results

The PHP language is designed for creating dynamic web pages.

  • The PHP code is contained between the tags.
  • The echo statement is designed to display text.
  • It is possible to include large blocks of text in the PHP code
  • PHP uses three types of comments: /* ... */, // and #.
  • The variable name is preceded by a dollar sign $, begins with a letter or underscore, and can be followed by any number of letters, numbers, or underscores.

Good day to everyone who wants to join the world of user scripts (aka userscript, userJS, userscripts).

In this article I want to tell you about what userscripts are, what they are eaten with and, most importantly, how they are prepared!

Attention: Minimal knowledge of javascript is assumed.
It has been proven in practice: user scripts can be written by a person who is not familiar with programming, but has perseverance and desire learn javascript!
You can learn about what javascript is and how to use it at javascript.ru.

What are userscripts? Briefly: a user script is a program written in JavaScript, stored on the user’s computer and connected by the browser on certain pages. A userscript is a file with the extension .user.js (it is by the extension that browsers understand that the file is a userscript), containing metadata and javascript code itself.

When connecting to a page, the user script is executed in the same way as regular javascript scripts.
The user script has access to the DOM tree of the page in the context of which it is executed.
In modern browsers, the userscript has access to localStorage and other HTML5 APIs.

Userscripts are supported all major modern browsers(and even somehow supported IE7 and higher).

The most famous userscript portal is userscripts.org. Here you can find a repository of scripts, tools for managing your scripts on the portal and, last but not least, a responsive forum (all in English).

A little general theory The most common are scripts for the GreaseMonkey extension for the Firefox browser.
Detailed information on GreaseMonkey and writing user scripts for GreaseMonkey can be found at http://wiki.greasespot.net.
It so happened historically that this browser was (and remains to this day) the first in which support for user scripts was performed at a high level.

Not all scripts written for GreaseMonkey can run in other browsers. The reason for the crookedness is that many scripts use the GM API - a set of javascript functions specific to GreaseMonkey.

However, the easiest way is to write user scripts for the Google Chrome browser.
There are a number of reasons for this:

  • Simple scripts do not need GM API support (library available in GreaseMonkey)
  • Google Chrome, unlike Firefox+GreaseMonkey, has an excellent debugger.
  • Userscript error messages in Firefox are terrible! Unless you have the gift of telepathy and a solid knowledge of GreaseMonkey and javascript, writing user script can be a pain!
  • Google Chrome does not require extensions to support user scripts. The interface for deleting/disabling user scripts is available out of the box.
  • Obvious disadvantages of Google Chrome:
  • No access to the “native” window.
  • The @include metadata directive is not supported. The @match directive is buggy, one might say that it is also not supported.
  • Features of user scripts The code of user scripts can be viewed by anyone armed with a notepad.
    Basic knowledge of javascript allows you to cut off the threat of installing spyware and malicious scripts by simply analyzing the script code (you will have to use your brain).

    All user scripts are launched after all the main elements of the page have loaded, but the images have not yet loaded. We can say that user scripts are loaded using the DOMContentLoaded event.
    In any case, checks on window.onload are not needed.

    Each browser imposes its own restrictions on the execution of user scripts, but in general User scripts can do almost everything that scripts on a page can do.
    Most often, user scripts are used to change the page interface or to add bonuses, blackjack and whores (user scripts for social networks).
    There are also advanced user scripts, which are independent programs (auction and gaming bots, assistant plugins, etc.).

    Anatomy of userscripts A userscript is a text file with the extension user.js. At the beginning of the file is located metadata block- description of the script itself. The metadata block is followed by javascript code, which will be executed by the browser.

    Let's consider a test script that displays an alert with text on a specific page.
    // ==UserScript== // @name myUserJS // @description My very first userscript // @author Vasya Pupkin // @license MIT // @version 1.0 // @include http://userscripts.org/* / / ==/UserScript== // Wrap the script in a closure for cross-browser compatibility (opera, ie) (function (window, undefined) ( // normalize window var w; if (typeof unsafeWindow != undefined) ( w = unsafeWindow ) else ( w = window; ) // Almost any javascript libraries can be inserted into user scripts. // The library code is copied directly into the user script. // When connecting the library, you need to pass w as a window parameter window // Example: connecting jquery.min.js // (function(a,b)(function ci(a) ... a.jQuery=a.$=d))(w); // do not run the script in frames // without this condition the script will be run several times on the frames page if (w.self != w.top) ( return; ) // additional check along with @include if (/http:\/\/userscripts.org/.test(w.location.href)) ( // Below is the script code itself alert("Userscripts greets you with an intrusive window."); ) ))(window);

    Important: This script is a wrapper for cross-browser user scripts. The same script, but with English comments, can be downloaded from pastebin.com and use it with impunity.

    At the very beginning there is a metadata block (in the form of a comment).
    // ==UserScript== // ... // ==/UserScript==
    This block consists of description directives userscript. The table below shows the main directives and their purpose.

    Important: All directives, like the metadata block itself, may be missing.

    Directive Purpose
    @name Name of the userscript.
    This name will be displayed in the management interface
    userscripts. If there is no directive, then the name
    The user script will be the same as the file name.
    @description Description of the userscript.
    This description will be displayed in the management interface
    userscripts.
    @namespace Namespace.
    Determines the uniqueness of a set of scripts.
    Here you can enter the name of the domain that belongs to you. Or any other line.
    Consider this the second name of the script. Mandatory Directive for Trixie!
    @author Author's name.
    @license The name of the license under which the user script is distributed.
    @version Userscript version number.
    Unfortunately, there is no auto-update mechanism in any browser,
    so the version number is just numbers that are displayed in the interface.
    @include
    on which you need to run the userscript.
    Supports wildcard *(applicable in GreaseMoneky, Opera, IE).
    For each separate url you need to use a separate @include directive.
    @exclude Page url description directive,
    on which you do not need to run the user script.
    Supports wildcard *(applicable in GreaseMonkey, Opera, IE).
    For each separate url you need to use a separate @exclude directive.
    @match Similar to @include, but with stricter restrictions
    (applicable in GreaseMonkey older than 0.9.8, Google Chrome).
    More information about the restrictions and format of the directive can be found here.
    read on this page.
    For each separate url you need to use a separate @match directive.

    Important: As practice has shown, you should not rely on the @match directive in user scripts.
    Google Chrome periodically refuses to honor @match
    and runs user scripts on all pages.
    To prevent such a situation in user scripts,
    which will run not only in Firefox,
    you need to add code for checking the page address (see link in the userscript code).

    Important: In the absence of @include or @match directives, userscripts will run on all pages.

    Our user script uses a number of tricks:

  • To ensure that user scripts have the same behavior and do not pollute the global scope, the code turns into a closure(see in the script code).
  • To correctly connect libraries inside a user script and to bypass some of the tricky features of GreaseMonkey, it is necessary to “normalize” the reference to the global window scope(see in the script code).
  • To ensure that the user script does not run several times on the same page, it is necessary stop work when running a userscript in frames(see in the script code).
  • In order for the user script to run only on the pages we need, it is necessary to explicitly check the page url (see in the script code).
  • Thanks to this structure, a userscript can be relatively easily converted into a bookmarklet.
  • Result Our user script is ready to use!
    No, seriously, you can copy the userscript code into a file, call it my.user.js, and drop the resulting file into your browser (use Chrome or Firefox with GreaseMonkey installed).

    Of course, our user script does not have serious functions; the code looks scary and unattractive (for the uninitiated person). But in the end we got a template for cross-browser user scripts.
    This means that the user script can be run in almost any modern browser!
    And that is great!

    The question remains: how to “distribute” our script to users (after all, we wrote the script not only for ourselves)?
    Options:

    • Register on the portal userscripts.org and upload scripts there.
    • Create a repository on code.google.com or github.com.
    • Create your own simple service/website/page.
      Important: If you want GreaseMonkey users to automatically open the user script installation dialog, upload the file directly from the file system (the file URL must end in .user.js). Otherwise, the user will see the script source code and a panel with an “install” button. This button doesn't work!
    Recipe for non-programmers (~70% of scripts are written using similar methods):
  • Let’s figure out what our user script will do (recolor links, for example)
  • We take the template from the article
  • Save to file my.user.js
  • Delete the line with alert(...) .
  • Let's go to the forum (userscripts.org or any javascript forum).
  • We spam, flood and pester people with questions like “how to recolor links”, “give me the code”, etc.
  • We change the metadata and verification of the page url to the ones we need.
  • We paste the code received from the forum into the userscript.
  • Save the file.
  • PROFIT!!1!
  • Useful links:

    Writing scripts in Linux (learning with examples)

    ———————————————————————————-

    1. Introduction

    What you need to write scripts
    Knowledge of command line tools and their required options.
    Basic knowledge of English at primary school level will not hurt.

    Why are scripts needed?
    Firstly, administering a Linux server to one degree or another comes down to systematically executing the same commands. Moreover, it is not necessary that these commands be carried out by a person. They can be programmed to be executed by a machine.
    Secondly, even just performing a regular task, which (suddenly) amounts to 20-1000... monotonous operations is MUCH easier to implement in a script.

    What is a script
    A script is a set of instructions that a computer must execute in a certain order and at a certain time. Instructions can be either internal shell commands (cycles, conditions, processing text information, working with environment variables, etc.), or any program that we execute in the console with the necessary parameters.

    How to write a script
    In our case, the script will be a text file with execution attributes. If a script file begins with the sequence #!, which in the UNIX world is called sha-bang, then this tells the system which interpreter to use to execute the script. If this is difficult to understand, then just remember that we will start writing all scripts with the line #!/bin/bash or #!/bin/sh, and then the commands and comments for them will follow.

    Parting words
    I sincerely advise you to write as many comments as possible on almost every line in the script. Time will pass and you will need to change or modernize the script you once wrote. If you don’t remember or don’t understand what is written in the script, then it becomes difficult to change it; it’s easier to write from scratch.

    What scripts might we need:

      setting firewall rules when the system boots.
      performing backup of settings and data.
      adding mailboxes to the mail server (more precisely to the mysql database)
      launching at a certain time (preferably every night) a program that scans the proxy server logs and produces a convenient web report on the amount of downloaded traffic.
      sending us information by email that someone has accessed our server via ssh, connection time and client address.

    About the method of writing scripts
    We create a text file, edit it, set execution rights, run it, look for errors, correct it, run it, look for errors...
    When everything is polished and working correctly, we put it in autoload or in the scheduler for a certain time.

    ———————————————————————————-

    2. Learning to write scripts in the internal BASH language
    original: https://www.linuxconfig.org/Bash_scripting_Tutorial

    This tutorial assumes no prior knowledge of how to write scripts using the internal Bash language. With the help of this guide, you will soon discover that writing scripts is a very simple task. Let's start our tutorial with a simple script that prints the string "Hello World!" (translated from English - Hello everyone!)

    1. Scenario “Hello everyone”
    Here's your first bash script example:

    #!/bin/bash
    echo "Hello World"

    Let's go to the directory containing our hello_world.sh file and make it executable:

    Code: Select all $ chmod +x hello_world.sh

    Running the script for execution

    Code: Select all $ ./hello_world.sh

    2. Simple archiving bash script

    #!/bin/bash
    tar -czf myhome_directory.tar.gz /home/user

    Code: Select all $ ./backup.sh

    $ du -sh myhome_directory.tar.gz
    41M myhome_directory.tar.gz

    3. Working with variables
    In this example, we declare a simple variable and display it on the screen using the echo command

    #!/bin/bash
    STRING=”HELLO WORLD!!!”
    echo $STRING

    Code: Select all $ ./hello_world.sh
    HELLO WORLD!!!

    Our archiving script with variables:

    #!/bin/bash
    OF=myhome_directory_$(date +%Y%m%d).tar.gz
    IF=/home/user
    tar -czf $OF $IF

    Code: Select all $ ./backup.sh
    tar: Removing leading "\" from member names
    $ du -sh *tar.gz
    41M myhome_directory_20100123.tar.gz

    3.1 Global and local variables

    #!/bin/bash
    # Declare a global variable
    # Such a variable can be used anywhere in this script
    VAR="global variable"
    function bash(
    # Declare a local variable
    # Such a variable is only valid for the function in which it was declared
    local VAR=”local variable”
    echo $VAR
    }
    echo $VAR
    bash
    # Note that the global variable has not changed
    echo $VAR

    Code: Select all $ ./variables.sh
    global variable
    local variable
    global variable

    4. Pass arguments to the script

    #!/bin/bash
    # Use predefined variables to access arguments
    # Print arguments to screen
    echo $1 $2 $3 ‘ -> echo $1 $2 $3’

    #We can also access arguments through a special array args=("$@")
    # Print arguments to screen
    echo $(args) $(args) $(args) ‘ -> args=(“$@”); echo $(args) $(args) $(args)’

    # Use $@ to print all arguments at once
    echo $@ ‘ -> echo $@’

    Use the $# variable to display the number of arguments passed to the script
    echo Number of arguments passed: $# ‘ -> echo Number of arguments passed: $#’

    Code: Select all $ ./arguments.sh Bash Scripting Tutorial
    Bash Scripting Tutorial -> echo $1 $2 $3
    Bash Scripting Tutorial -> args=("$@"); echo $(args) $(args) $(args)
    Bash Scripting Tutorial -> echo $@
    Number of arguments passed: 3 -> echo Number of arguments passed: $#

    5. Executing shell commands in a script

    #!/bin/bash
    # use backquotes " ` ` " to execute a shell command
    echo `uname -o`
    # now let's try without quotes
    echo uname -o

    Code: Select all $ uname -o
    GNU/Linux
    $ ./bash_backtricks.sh
    GNU/Linux
    uname -o

    As you can see, in the second case the command itself was displayed, and not the result of its execution

    6. Reading user input (interactivity)

    #!/bin/bash
    echo -e "Hi, please type the word: \c "
    read word
    echo "The word you entered is: $word"
    echo -e “Can you please enter two words? »
    read word1 word2
    echo "Here is your input: \"$word1\" \"$word2\""
    echo -e “How do you feel about bash scripting? »
    # read command now stores a reply into the default build-in variable $REPLY
    read
    echo “You said $REPLY, I’m glad to hear that! »
    echo -e “What are your favorite colors? »
    # -a makes read command to read into an array
    read -a colors
    echo “My favorite colors are also $(colours), $(colours) and $(colours):-)”

    Code: Select all $ ./read.sh
    Hi, please type the word: something
    The word you entered is: something
    Can you please enter two words?
    Debian Linux
    Here is your input: "Debian" "Linux"
    How do you feel about bash scripting?
    good
    You said good, I"m glad to hear that!
    What are your favorite colors?
    blue green black
    My favorite colors are also blue, green and black:-)

    7. Using a trap

    #!/bin/bash
    # declare a trap
    trap bashtrap INT
    # clear the screen
    clear;
    # The hook function is executed when the user presses CTRL-C:
    # The screen will display => Executing bash trap subrutine !
    # but the script will continue to run
    bashtrap()
    {
    echo "CTRL+C Detected !…executing bash trap !"
    }
    # the script will count up to 10
    for a in `seq 1 10`; do
    echo "$a/10 to Exit."
    sleep 1;
    done
    echo "Exit Bash Trap Example!!!"

    Code: Select all $ ./trap.sh
    1/10
    2/10
    3/10
    4/10
    5/10
    6/10

    7/10
    8/10
    9/10
    CTRL+C Detected !...executing bash trap !
    10/10
    Exit Bash Trap Example!!!

    As you can see, the Ctrl-C key combination did not stop the execution of the script.

    8. Arrays
    8.1 Declaring a simple array

    #!/bin/bash
    # Declare a simple array with 4 elements
    ARRAY=('Debian Linux' 'Redhat Linux' Ubuntu Linux)
    # Get the number of elements in the array
    ELEMENTS=$(#ARRAY[@])

    # loop through each element of the array
    for ((i=0;i /dev/null convenient if you archive a large number of files. In this case, their names and full path to them are not displayed on the console.

    The next step is to provide hints to the user on how to use the script if he makes any mistakes.

    For example, this design

    If [ $# -lt "$MAXPARAMS" ];
    then
    echo

    echo
    exit 0
    fi

    will indicate that the user has not specified enough command line arguments. If [condition]...fi specifies a conditional construction. $# -lt "$MAXPARAMS" checks the entered number of parameters and if this number is less than MAXPARAMS, the user will receive a message indicating an erroneous input. Exit 0 will cause the script to terminate without specifying an error code. The excess of the permissible number of parameters is checked in a similar way, only instead of ls (less then - less than), you must specify gt (greater then - greater than). Now that the main points of the script are explained, we can move on to its full version:

    #!/bin/bash
    # Description:
    #+ Makes a backup copy of all files in the specified directory
    #+ in "tarball" (tar.gz archive).
    #+ Usage:
    #+ sh backup.sh archive_name source folder destination folder
    #+

    # Maximum number of command line parameters
    MAXPARAMS=3

    if [ $# -lt "$MAXPARAMS" ];
    then
    echo
    echo "Usage: sh `basename $0` archive_name source folder destination folder"
    echo
    exit 0
    fi

    if [ $# -gt "$MAXPARAMS" ];
    then
    echo
    echo "This script only requires $MAXPARAMS command line arguments!"
    echo
    exit 0
    fi

    # Variables we use in the script
    BACKUPFILE=$1-backup-$(date +%m-%d-%Y)
    archive=$BACKUPFILE
    BACKUPDIR=$2
    ARCHIVEDIR=$3

    # Check if there is a source folder and a destination folder
    if [! -e $BACKUPDIR ];
    then
    echo
    echo "\"$BACKUPDIR\" does not exist!"
    echo
    exit 0
    fi

    if [! -e $ARCHIVEDIR ];
    then
    echo
    echo "\"$ARCHIVEDIR\" does not exist, creating..."
    mkdir $ARCHIVEDIR
    echo "Done."
    fi

    # Check if there are archives in the source and destination.
    cd $ARCHIVEDIR
    if [ -e $archive.tar.gz ];
    then rm $archive.tar.gz
    fi

    cd $BACKUPDIR
    if [ -e $archive.tar.gz ];
    then rm $archive.tar.gz
    fi

    # The main part of the script...
    echo "Making a backup copy of \"$BACKUPDIR\" to the file \"$archive.tar.gz\"..."
    find . -type f -print0 | xargs -0 tar rvf "$archive.tar" > /dev/null
    gzip $archive.tar
    echo "\"$BACKUPDIR\" was successfully archived to the file \"$archive.tar.gz\"."

    # Move the archive to the ARCHIVEDIR folder
    echo "Moving the archive \"$archive.tar.gz\" to the folder \"$ARCHIVEDIR\"."
    mv $archive.tar.gz $ARCHIVEDIR/$archive.tar.gz
    echo "Done."

    I hope I have commented on the main points in sufficient detail. If you have any questions, you can contact me at [email protected] I also recommend the wonderful book Advanced Bash-Scripting Guide by Mendel Cooper, which helped me a lot when I was just getting acquainted with scripts. Happy programming.

    P.S. Many thanks to mar for her comments and advice.

    How to write a sales script? This question is probably asked by everyone who works in sales. And this is not surprising - after all, a good sales script will allow you to attract customers faster and easier, help managers overcome objections and answer questions from potential buyers. The advantages of using the script are obvious.

    But there is also a downside.

    Developing a sales script is not an easy task. In the article “3 ways to write and execute a sales script” I have already shared with you my opinion on preparing a script (electronic format, paper format).

    Today I want to offer you a script creation scheme - a 9-step algorithm for writing a script from scratch (we are talking about writing a cold call script. For other types of calls, the algorithm will be similar with minor adjustments). When I create sales scripts for corporate clients, I myself rely on this algorithm.

    I have prepared the algorithm in PDF format. You can download it for free by unlocking access via (click on any social media button).

    I described each step in more detail in these videos:

    How to write a sales script: step 1-5 (video)

    Let's look at the basic steps when writing a script.

    1. Start with segmentation

    This step (unfortunately, unfamiliar to most) allows us to initially divide the base of our potential clients into those that are more promising and interesting to us and those that are less interesting. At this step, it is important to determine the segmentation criteria for your situation. For example, if I sell sales training, then for me a client with a sales department in the company and untrained employees will be much more interesting than a client without a sales department at all. Thus, we identify categories of clients A, B, C and further as necessary for your business. I discussed this important step in more detail during the online training (here you can see the report from the training), but I think the logic of segmentation is clear to you.

    2. Determine the target action

    At this step, it is important to plan for each customer segment those targeted actions that will be beneficial to us. For example, with clients of category A, we are ready to meet on the client’s premises (since they are the most promising and interesting to us. We are ready to invest our time in such clients), and with clients of category C, for example, we can limit ourselves to subscribing to the newsletter.

    3. Determine the decision maker

    The decision maker is the decision maker. Who in your case determines the decision to work with you? Often managers rush their way to the manager, not realizing that the decision on their issue in the company is probably made by another person. This is an important step that directly affects filling our script with effective speech patterns.

    4. Fill out your target list

    A target list is a list of companies to attract. I recommend having a small list of those you want to call already in the process of writing the script.

    5. Think about reaching out to the decision maker

    What will you tell the secretary so that he can connect you with the manager? Usually 2-3 techniques are enough for me to bypass almost any secretary. In the 10 calls - 10 sales course, I talk about such techniques.

    6. Determine the ideal line of conversation with the decision maker

    Imagine that your conversation is going perfectly smoothly. The client doesn't mind. Think about where you will start the conversation, how you will build contact, and how you will argue your position. I usually highlight 4 components in this block, which I will talk about in another article (the “VUUZ” technique).

    7. Add branching

    The sales script implies different options for customer behavior. He may agree with you right away (in which case your ideal line of conversation will work), or he will refuse and object. At step 7, it is important to foresee possible refusals and excuses from the client. I usually distinguish between universal objections (they can appear on any node in the script) and nodal objections (they can only appear on a specific node. For example, during the establishment of contact). The course will help you overcome any objections. It has all the necessary techniques to handle any objections.

    8. Automate the script

    At this step, I recommend automating the sales script. You can use templates for automation (for example, I used an Excel template in the course), or special services for automating scripts (I like).

    9. Improve!

    Monitor the conversion of each node and the script as a whole, try different answers to objections and methods of argumentation. And you will have a killer sales script!

    P.s. I discussed the technology of creating scripts in more detail at the online training (or rather, workshop) Sales scripts that work. Look at the details about how the event went, what conclusions I drew for myself during communication with the participants. Perhaps this will be useful for you and your situation.

    Useful links:
    • Attend a free webinar to learn the most effective telesales strategies for your business
    • Sales call checklist of 14 steps ()
    • Subscribe to the Youtube channel “It’s time to grow” and we will develop and grow together
    • Upgrade your sales skills. Perhaps one of the best budget solutions on the Internet that will help you and your employees increase sales!
    • Sales scripts: 9 steps to create a script with...
    • Walking around the secretary. 4 techniques for a sales script with...




    

    2024 gtavrl.ru.