Reputation: 21
I need to write a bash script that captures user input URL and downloads the URL using wget, saving to user determined folder.
Having trouble with the URL in my if statement
script:
#!/bin/bash
until [[ $REPLY = "exit" ]]
do
read -p "Please type the URL of a file to download or type "exit" to quit: " REPLY
echo
if [[ $REPLY = "$url" ]]; then
read -p "Please type your download location: " user_dir
mkdir -p $user_dir &&
wget $url -o $user_dir
fi
done
echo "Thank you. Goodbye!"
exit 0
Upvotes: 1
Views: 512
Reputation: 1
curl 'https://www.roblox.com/games/8310127828/Cabin-Roleplay'
-H 'authority: www.roblox.com'
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7'
-H 'accept-language: tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7'
-H 'cache-control: max-age=0'
-H 'cookie: GuestData=UserID=-2039980655; gcl_au=1.1.1940905455.1704543019; RBXcb=RBXViralAcquisition=true&RBXSource=true&GoogleAnalytics=true; RBXSource=rbx_acquisition_time=1/6/2024 6:10:21 AM&rbx_acquisition_referrer=https://www.roblox.com/&rbx_medium=Direct&rbx_source=www.roblox.com&rbx_campaign=&rbx_adgroup=&rbx_keyword=&rbx_matchtype=&rbx_send_info=1; RBXEventTrackerV2=CreateDate=1/6/2024 6:11:10 AM&rbxid=3281316906&browserid=214189704320; __stripe_mid=7a7659b8-8d37-4360-9e61-106f0d7d6fc5c0e0a4; .ROBLOSECURITY=|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_9448883811703EE25DF0883A23FAD726AFB5E2971016B678131F4302FB98F60126FB748B1CB3E5599252FCC5CA163BE830078F15AA7F71DA70FD1D6342127AF22C44690BE49524B7C59E1235545493143A4FA65D28DD32845F1201290A580CA3C97C8F3CB18F736678058AD656F1958DBAF60185992C44E9219BD8FB89CBA90D9CAD31A8C43A0DA53837E0870ECB8385F7618294CB62A06F9025047D2DAA7A010D0C3E2D30CB7002F25A99DDFE8FD88C651F9CC20A382587F7742C4EEF54DAE07966DD67DE0F088F7DEAEAC27590647C5B115E1BD765DC91BB41DEFAD7D5666ED059B1ED87FD7F600E97DF6658EF42B3E4ACE6C8461A9EC64B31161AF06930DD99A33D589E6F84AC7290D2C8A5A29B15A952AA28B4F1CBC8D333F25EF2965D19B04FBCD78310D198B8FA61219EDF3852931B706AC6BD64C1CD29D5F948DA519528B5AEA174DB254ADF32B9F4A97EDD1C33812B86CB95B971FD213E96C6EFA8B56DCFC00F5094B8DDC12A644107FB59EB67BD30ED1A5F2FCEEFECBBB14E42915F0B635A1D54FC757CFB01395076B2D213A9A86E7E4E3B8D53D0DA99D6BF9F2EE70542CCDDFBC3CC58A7CADAF756721477AA6FF8E187003D8B30B4EC09F0F8145128E898A7FA5E5B7BE75084665714F4F1B66F047E03292448D5B3398D75B590836860FE6138F398519F8C1B5516504B630E2C8BB5459D74B5FD4AD9AF1DA9A9CDA6C082E33381B97A63FE3D101AE27E2CDE4B7BD25D7E70718833519818FC9D0B4190FC283A377B42DC371C574A962824BDB4D28CF9568C6F24A092D9F2B711C8BE54C894658744B10300BF5BD6E4B0228344185D3B7E8191D53E3D7D632597CC4808E99E28F8DA7A113AF368957AD497DDDB0958FD345E42B29C5717C5FA9EFD2E62619B131C32EA1876F01757FFF7849CD587B6E31E35F4F7F0A6E4F0F2D10F2DF01B4B96A65E894EAAE572001D1C4072E40DF9E890FC7E4AFC08B2379EEFA4F1FDB46B65CB77B9BF33369C6C5AAAE5FA4FD864049299CFF82431074BEE7D314C2768D2; .RBXIDCHECK=8b4b6310-8aa0-41a1-b770-30e48cba17bd; rbxas=7de5f412a132a24966a893966df7f72ca612f18ea8787d5daa8c3f58c9e06c32; _ga=GA1.1.80205856.1704626233; _ga_BK4ZY0C59K=GS1.1.1704911185.6.0.1704911192.0.0.0; __utmz=200924205.1704911198.9.9.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); rbx-ip2=; RBXSessionTracker=sessionid=6ff525e1-4f6e-4a2d-aae5-1b8bb56e9480; __utma=200924205.368449108.1704543035.1705220300.1705223691.16; __utmb=200924205.0.10.1705223691; __stripe_sid=63da33a1-1d94-4e9d-a917-fec60c5bcc49bab02e; __RequestVerificationToken=l1IUUGWP0BX46rpvEp3HHd_PFNKW7RFp2vA9zqBQ3bx1HLxhoK6g1NbvcHAPsOt5f5fItbhPw7MFP1P5MSXNSfTnk941; __utmc=200924205'
-H 'sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"'
-H 'sec-ch-ua-mobile: ?0'
-H 'sec-ch-ua-platform: "Windows"'
-H 'sec-fetch-dest: document'
-H 'sec-fetch-mode: navigate'
-H 'sec-fetch-site: same-origin'
-H 'sec-fetch-user: ?1'
-H 'upgrade-insecure-requests: 1'
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
--compressed
Upvotes: -1
Reputation: 2091
Try this
#!/bin/bash
until [[ $url = "exit" ]]
do
read -p "Please type the URL of a file to download or type exit to quit: " url
if [[ $url == "https://"* ]] || [[ $url == "http://"* ]]; then
read -p "Please type your download location: " user_dir
mkdir -p $user_dir
wget $url -P $user_dir
else
echo "No valid url"
fi
done
echo "Thank you. Goodbye!"
Some changes that I made:
wget
you must use -P
not -o
[[ $REPLY = "$url" ]];
I assumed that you want to check url schema(I'm not doing a complete schema url validation, but you'll get the idea).mkdir &&
so i removed it, as i think is not necessary here, also I removed a echo
.Upvotes: 1