Extracting file with folders then using bash completion

Viewed 37

I don't work much with bash scripting and was trying to do something like this:

#!/bin/bash
wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-i686-static.tar.xz
tar xvf ffmpeg-git-i686-static.tar.xz
cd ./ffmpeg-git-20210501-i686-static/
cp ./ffmpeg-git-20210501-i686-static/ffmpeg /etc/bin

Is there a variable or a way I can determine what that extracted folder is called during script execution. For example with bash completion at the command line I would use cd ./ffmpeg (since I know it starts with ffmpeg)

Make sense?

1 Answers

There is no way to know beforehand the directory structure, but you can use a wildcard in the copy command:

cp ./*/ffmpeg /etc/bin

Although, I do not recommend installing tarball extracted executable within /etc/bin.

I'd put a symbolic link inside /usr/local/bin/ instead:

#!/usr/bin/env sh

__opwd="$PWD"
trap 'cd "$__opwd"' EXIT ABRT INT

wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-i686-static.tar.xz || exit 1

# Create place where to install the unpacked archive
mkdir -p '/opt/ffmpeg-git-i686-static' || exit 1

# Unpack the archive
cd '/opt/ffmpeg-git-i686-static' || exit 1
tar xf "$__opwd/ffmpeg-git-i686-static.tar.xz" || exit 1

# Create a symbolic link from the ffmpeg command into `/usr/local/bin/`
ln -sf /opt/ffmpeg-git-i686-static/*/ffmpeg /usr/local/bin/
Related