Skip to main content
Salespitch
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    mkdir -p -- "$2" &&
        cp -p -- "$1" "$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

An advantage of this approach is that you can have the utility to exactly what you want. This implementation requires a directory as its second argument but you could equally adapt it to expect a file pathname as the second argument. It's whatever works best for you.

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    mkdir -p -- "$2" &&
        cp -p -- "$1" "$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    mkdir -p -- "$2" &&
        cp -p -- "$1" "$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

An advantage of this approach is that you can have the utility to exactly what you want. This implementation requires a directory as its second argument but you could equally adapt it to expect a file pathname as the second argument. It's whatever works best for you.

Reverted misunderstanding
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    local src="$1" dst="$2"
    mkdir -p -- "$(dirname -- "$dst")""$2" &&
        cp -p -- "$src""$1" "$dst""$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

Lose local and replace the {/} with (/) if you want strict POSIX compliance.

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    local src="$1" dst="$2"
    mkdir -p -- "$(dirname -- "$dst")" &&
        cp -p -- "$src" "$dst"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

Lose local and replace the {/} with (/) if you want strict POSIX compliance.

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    mkdir -p -- "$2" &&
        cp -p -- "$1" "$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c
missing --s, src/dst weren't used. Need the dirname of dst, use () for local scope in POSIX
Source Link
Stéphane Chazelas
  • 584.7k
  • 96
  • 1.1k
  • 1.7k

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    local src=$1src="$1" dst=$2dst="$2"
    mkdir -p "$2"-- "$(dirname -- "$dst")" &&
        cp -p "$1"-- "$2""$src" "$dst"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

Lose local and replace the {/} with (/) if you want strict POSIX compliance.

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    local src=$1 dst=$2
    mkdir -p "$2" &&
        cp -p "$1" "$2"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

Lose local if you want strict POSIX compliance.

You can roll your own command too. Here's a function implementation but you could equally drop a variant of this into an executable script somewhere along your $PATH

mdcopy() {
    local src="$1" dst="$2"
    mkdir -p -- "$(dirname -- "$dst")" &&
        cp -p -- "$src" "$dst"
}

Usage

mdcopy /a/b/c/xxxxx.sql /a/b/d/c

Lose local and replace the {/} with (/) if you want strict POSIX compliance.

added 6 characters in body
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323
Loading
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323
Loading