Announcement

Collapse
No announcement yet.

Microsoft's PowerShell Now Available On Ubuntu In Snap Form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Ok, so let's start migrating all our shell scripts to power shell... But no

    Hehe

    Comment


    • #22
      Originally posted by anarki2 View Post

      You never thought, a lot of others, including me, do. It's incomparably handier compared to "oh I need some info let's cat and grep and awk and tail and cut" bash or "why doesn't my code work, oh it's a missing space" python.

      The only advantage of these two is being ubiquitous. Most scripts are written in bash because it can be taken for granted, not because it's "good". It sucks ass when it's anything longer than 5 lines, especially when it comes to things like error handling. Just look at this piece of crap:

      Code:
      wget -nv --content-on-error "${IMAGE_BASE}/${UNAME}.jpg" -O ${AVATAR_FILE} || true
      # continue if grep doesn't match, but preserve the match state anyway
      RET=1
      file ${AVATAR_FILE} | grep -i jpeg && RET=$? || true
      That's error "handling" in bash for ya. Stupid, stupid, stupid.
      He was talking of using python, why are you pulling out bash? Bash is a shell, a CLI interface with usable scripting capabilities (better than windows's CMD.EXE anyway), it's not a proper scripting language by a long shot.

      Comment


      • #23
        Originally posted by anarki2 View Post
        Code:
        wget -nv --content-on-error "${IMAGE_BASE}/${UNAME}.jpg" -O ${AVATAR_FILE} || true
        # continue if grep doesn't match, but preserve the match state anyway
        RET=1
        file ${AVATAR_FILE} | grep -i jpeg && RET=$? || true
        That's error "handling" in bash for ya. Stupid, stupid, stupid.
        Let's ignore the fact that this bash script doesn't make any sense and ask: how would this script look like in PowerShell?

        Comment


        • #24
          You can do many things directly with bash as you can execute any tool very easy. For parsing you work with strings only. This is much simpler than using objects in PowerShell. The syntax is a bit like SQL and extreme usage of pipes. I would not say that it was designed as bash replacement, even cmd can solve some basic things much faster (on Windows). Use what best suits for the problem to solve.

          Comment


          • #25
            PowerShell = scripting objectified (.NET + registry) system and services. If you would want to manage Windows and Linux with the same set of scripts, PowerShell would be a good tool for that. Oh wait, one would need .NET for Linux then... https://docs.microsoft.com/en-us/dot...-prerequisites

            Comment


            • #26
              Originally posted by anarki2 View Post
              or "why doesn't my code work, oh it's a missing space" python.
              Have you used Python before? I've used it a fair bit and I cannot recall a single time I've had a problem related to spaces, tabs or new lines.

              My main issues with python have revolved around handling dependencies and also the module importing system. Other than those it's a great language for what it's designed for.

              Comment


              • #27
                Originally posted by cybertraveler View Post

                Have you used Python before? I've used it a fair bit and I cannot recall a single time I've had a problem related to spaces, tabs or new lines.
                Indeed, that complaint is the easiest way to spot someone who doesn't know what they're talking about.

                Comment


                • #28
                  Originally posted by anarki2 View Post
                  The only advantage of these two is being ubiquitous. Most scripts are written in bash because it can be taken for granted, not because it's "good". It sucks ass when it's anything longer than 5 lines, especially when it comes to things like error handling. Just look at this piece of crap:

                  Code:
                  wget -nv --content-on-error "${IMAGE_BASE}/${UNAME}.jpg" -O ${AVATAR_FILE} || true
                  # continue if grep doesn't match, but preserve the match state anyway
                  RET=1
                  file ${AVATAR_FILE} | grep -i jpeg && RET=$? || true
                  That's error "handling" in bash for ya. Stupid, stupid, stupid.
                  Please demonstrate your PowerShell equivalent in a similar number of lines.

                  Comment


                  • #29
                    Quick, what does "-a" mean? Is it append? append-to-logfile? after? ASCII? archive? all users? all files? all man pages? auto-select best available compression algorithm? And do you put "-a" before the other parameters? After? Anywhere? Can you mix input flags with things like -alhF, or does the -a need to be by itself? If you have to give it a value, can you do -aFoo, or -a Foo, or -a=Foo, or any one of the three? With bash the answer to all of those questions depends upon the command you use. PowerShell is beautifully consistent, parameter orders, command flag formatting, and so forth are the same everywhere.

                    And even though PowerShell is object-focused, it has its equivalents to grep, awk, sed, cut, less, etc... so you can basically write all of your commands like this: Get-SomeDotNetObject | Select-The-Text-Information-You-Want-From-The-Object (you can even select multiple text fields in one command) | Do-Plain-Old-String-Processing

                    I already know bash and I'm lucky enough not to work with Windows Server at my job. So I just played with PowerShell enough to get a feel for it, but otherwise I don't care and probably won't ever learn it. But if I was someone both working in an environment that includes some Windows Servers and also new to shell scripting, I would prefer PowerShell to bash.

                    And Microsoft has open sourced all of it, so it's no longer an EEE danger.

                    Comment


                    • #30
                      Originally posted by Michael_S View Post
                      Quick, what does "-a" mean? Is it append? append-to-logfile? after? ASCII? archive? all users? all files? all man pages? auto-select best available compression algorithm? And do you put "-a" before the other parameters? After? Anywhere? Can you mix input flags with things like -alhF, or does the -a need to be by itself? If you have to give it a value, can you do -aFoo, or -a Foo, or -a=Foo, or any one of the three? With bash the answer to all of those questions depends upon the command you use. PowerShell is beautifully consistent, parameter orders, command flag formatting, and so forth are the same everywhere.

                      And even though PowerShell is object-focused, it has its equivalents to grep, awk, sed, cut, less, etc... so you can basically write all of your commands like this: Get-SomeDotNetObject | Select-The-Text-Information-You-Want-From-The-Object (you can even select multiple text fields in one command) | Do-Plain-Old-String-Processing

                      I already know bash and I'm lucky enough not to work with Windows Server at my job. So I just played with PowerShell enough to get a feel for it, but otherwise I don't care and probably won't ever learn it. But if I was someone both working in an environment that includes some Windows Servers and also new to shell scripting, I would prefer PowerShell to bash.
                      Short options generally don't have or get used with parameters. It wouldn't be -a Foo, it would be --all-files=1.

                      Most commands are of the form:

                      COMMAND-NAME OPTIONS FILE

                      Most OPTIONS are GNU style which means short options can be appended together such that -a -f -1 can be contracted down to -af1. Long options have 2 leading dashes and parameters can be passed to them using an equals delimiter. Most commands seem to accept both an equals delimiter or space (new parameter) delimiter.

                      Indeed, "-a" doesn't mean the same thing everywhere, but that would not be practically possible when you consider their are only about 62 possible combinations (upper case letters, lowercase letters and numbers). There are however very common conventions, eg:
                      • -h will almost always print help info and exit
                      • -V will almost always print a version number and exit
                      • -v will almost always increase output verbosity
                      • -q will almost always make the command quiet (no output on stdout)
                      • - will almost always mean get input from stdin instead of from a FILE
                      There are many common and widely followed conventions in UNIX, bash, GNU, POSIX and in Linux distros.

                      Regular users of bash will often quickly remember the meaning of common short options.

                      POSIX (including the shell and the common commands) is not perfect but it's good enough, it's powerful and it's widely available.

                      Lots of people also happen to already 'speak' the POSIX language and they don't want to learn a new and unpopular language when POSIX serves them well. As a speaker of POSIX I can tell you purely from my own memory that -a...
                      • in tar means select a compression algorithm based on the file extension
                      • in man means show all man pages one after the other.
                      • in ls means show hidden files in the output (I think it also shows . and ..)
                      • in rsync means use 'archive' mode
                      • in netstat means that the listening sockets should also be shown
                      I can't tell you a single PowerShell option. I don't even know what PowerShell options look like. There's no way that PowerShell is going to gain significant traction in the GNU/Linux world. It's a whole new language that none of us speak that came from an organisation that many of us despise.

                      Comment

                      Working...
                      X