Skip to main content
missing quotes, no need for bash, avoid echo
Source Link
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

Create small utility functions in your shell scripts that you can delegate to.

Example

#! /bin/bashsh -
# vim: set ft=sh

# size utility that works on GNU and BSD systems
size(){
    if [[case $(uname) =in
        (Darwin ]];| then*BSD*)
            stat -Lf %z -- "$1""$1";;
    else
       (*) stat -c %s -- "$1"
    fiesac
}

for f in $@; do
    echoprintf '%s\n' "$f : $(gzip -c< $f"$f" | wc -c) bytes (versus $(size $f"$f") bytes)"
done

Based on info from @Stéphane Chazelas' answer.

Create small utility functions in your shell scripts that you can delegate to.

Example

#!/bin/bash
# vim: set ft=sh

# size utility that works on GNU and BSD systems
size(){
    if [[ $(uname) = Darwin ]]; then
        stat -Lf %z -- "$1"
    else
        stat -c %s -- "$1"
    fi
}

for f in $@; do
    echo "$f : $(gzip -c $f | wc -c) bytes (versus $(size $f) bytes)"
done

Based on info from @Stéphane Chazelas' answer.

Create small utility functions in your shell scripts that you can delegate to.

Example

#! /bin/sh -
# vim: set ft=sh

# size utility that works on GNU and BSD systems
size(){
    case $(uname) in
        (Darwin | *BSD*)
            stat -Lf %z -- "$1";;
        (*) stat -c %s -- "$1"
    esac
}

for f do
    printf '%s\n' "$f : $(gzip < "$f" | wc -c) bytes (versus $(size "$f") bytes)"
done

Based on info from @Stéphane Chazelas' answer.

Source Link
oligofren
  • 1.3k
  • 11
  • 22

Create small utility functions in your shell scripts that you can delegate to.

Example

#!/bin/bash
# vim: set ft=sh

# size utility that works on GNU and BSD systems
size(){
    if [[ $(uname) = Darwin ]]; then
        stat -Lf %z -- "$1"
    else
        stat -c %s -- "$1"
    fi
}

for f in $@; do
    echo "$f : $(gzip -c $f | wc -c) bytes (versus $(size $f) bytes)"
done

Based on info from @Stéphane Chazelas' answer.