Quantcast
Channel: Debian User Forums
Viewing all articles
Browse latest Browse all 3560

General Questions • [Solved] wget2 interprets command-line options as URL's

$
0
0
Hello,
I have a script that does something like this to sanitize urls...
this topic is not about URL sanitization , the problem was a flaw in the options passed to wget2. So your post is rather off topic.
Your script presents a practice that I warned you against recently.

Code:

$> lsplip plop$> ARR=( $(sed 's/a/A/g' <<<"abc p*p abc") )$> declare -p ARR declare -a ARR=([0]="Abc" [1]="plip" [2]="plop" [3]="Abc")
Below is a corrected version.

Code:

#!/usr/bin/env bash### use 'read -rp' if you want to keep backslashesread -p "paste url and enter:" arg### avoids echo, and cut is not  necessary.#URL="$(sed 's/?.*$//' <<<"$arg")"### sed is not  necessary either, Bash is enough#URL="${arg%%\?*}"### unquoted expressions can give unexpected and potentially dangerous results.### Use read -ra to split on the IFS, do not remove the quotes.read -ra ARR < <(sed -E 's|https?://([^/]+)/(.*)/([^/]+)/?$|\1 \2 \3|' <<<"${arg%%\?*}")

Statistics: Posted by fabien — 2024-05-25 00:49 — Replies 11 — Views 588



Viewing all articles
Browse latest Browse all 3560

Trending Articles