What is a .sh file?

So, I do not have experience with many file types, and I could not find much information about what exactly .sh files represent. Here is what I am trying to do:

I am trying to download map datasets that are arranged as tiles, which can be downloaded separately: http://daymet.ornl.gov/gridded

To download several fragments at once, say, load their script, which ultimately leads to daymet-nc-retrieval.sh : https://github.com/daymet/scripts/blob/master/Bash/daymet-nc-retrieval.sh

So what exactly should I do with this code? The website does not give further instructions, suggesting that users know what to do with it. I assume that you should paste the code into some other uninterrupted browser application (in this case, using Chrome or Firefox)? It almost looks like something that can be inserted into Firefox / Greasemonkey, but not quite. Just fast Google by type of file, I could not get heads or tails on it.

I am sure that there is a simple explanation of what to do with these files, but it seems that he is buried in a large number of messages, where people already assume that you know what to do with these files. Anyone who just wants to say what needs to be done with the square after he got to the code page to implement it? Thank.

+51
linux sh download-manager
Dec 10 '12 at 16:45
source share
7 answers

If you open the second link in a browser, you will see the source code:

 #!/bin/bash # Script to download individual .nc files from the ORNL # Daymet server at: http://daymet.ornl.gov 

[...]

 # For ranges use {start..end} # for individul vaules, use: 1 2 3 4 for year in {2002..2003} do for tile in {1159..1160} do wget --limit-rate=3m http://daymet.ornl.gov/thredds/fileServer/allcf/${year}/${tile}_${year}/vp.nc -O ${tile}_${year}_vp.nc # An example using curl instead of wget #do curl --limit-rate 3M -o ${tile}_${year}_vp.nc http://daymet.ornl.gov/thredds/fileServer/allcf/${year}/${tile}_${year}/vp.nc done done 

So this is a bash script. Is there Linux?




In any case, a script is nothing more than a series of HTTP searches. Both wget and curl are available for most operating systems, and almost all languages ​​have HTTP libraries, so rewriting them in any other technology is quite simple. There are also some windows ports for bash itself (there is one in git). Last but not least, Windows 10 now has built-in support for Linux binary files .

+33
Dec 10
source share

What is a .sh file?

This is a Bourne shell script . They are used in many variations of UNIX-like operating systems. They do not have a "language" and are interpreted by your shell (interpreter of terminal commands) or, if the first line has the form

 #!/path/to/interpreter 

they will use this particular translator. Your file has the first line:

 #!/bin/bash 

and that means that he uses the Bourne Again Shell, the so-called bash. This is for practical purposes a replacement for the good old w.

Depending on the translator, you will have a different language in which the file is written.

Keep in mind that in the UNIX world, this is not a file extension that determines what the file is (see How to execute a shell script).

If you come from the world of DOS / Windows, you will be familiar with files with the extensions .bat or .cmd (batch files). They are not similar in content, but similar in design.

How to execute a shell script

Unlike some dumb operating systems, * nix does not rely solely on extensions to determine what to do with the file. Permissions are also used. This means that if you try to run a shell script after loading it, it will be the same as trying to "run" any text file. The extension ".sh" exists only for your convenience, to recognize this file.

You will need to make the file executable. Suppose you downloaded your file as file.sh , then you can run it in your terminal:

 chmod +x file.sh 

chmod is a command to change the permissions of a file, +x sets the execution rights (in this case for everyone), and finally, you have the name of your file.

You can also do this in a graphical interface. Most of the time, you can right-click on a file and select properties, in XUbuntu, the permission settings look like this:

File permissions in XUbuntu

If you do not want to change permissions. You can also force the shell to execute a command. In the terminal you can run:

 bash file.sh 

The shell should be the same as in the first line of your script.

How safe is it?

It may seem strange that in order to execute a file you need to complete one more task manually. But this is partly due to the strong need for security.

Basically, when you download and run a bash script, this is the same as someone tells you: "Run all of these commands in sequence on your computer, I promise that the results will be good and safe." Ask yourself if you trust the party that provided this file, ask yourself if you are sure that you downloaded the file from the same place as you thought, maybe even look inside to see if something looks inappropriate (although this requires that you know something about * nix commands and bash programming).

Unfortunately, apart from the warning above, I cannot give a step-by-step description of what you should do to prevent evil things from happening to your computer; so just keep in mind that every time you get and run an executable from someone who actually says, “Of course, you can use my computer to do something.”

+70
Aug 28 '15 at 4:42 on
source share

sh files are unix shell (linux) executable files; they are equivalent (but much more powerful) bat files on windows.

So, you need to run it from linux console by simply typing its name in the same way as bat files in windows.

+28
Dec 10
source share

Typically, a .sh file is a shell script that you can execute in a terminal. In particular, you mentioned a bash script that you can see if you open the file and look in the first line of the file called shebang or the magic line.

+4
Dec 10
source share

I know this is an old question, and I probably won’t help, but many Linux distributions (like ubuntu) have a “Live cd / usb” function, so if you really need to run this script, you can try downloading your Linux computer Just write .iso to the USB flash drive (here http://goo.gl/U1wLYA ), start the computer with the drive connected and press the F key for the boot menu. If you select "... USB ...", you will boot into the OS that you just put on the disk.

+1
Aug 28 '15 at 3:58
source share

The .sh file is a shell file. It can be used to open programs and what not.

+1
May 28 '16 at 18:15
source share

open the location in the terminal, then enter these commands 1. chmod + x filename.sh 2 ../ filename.sh what it

0
Feb 12 '17 at 9:46 on
source share



All Articles