shy-guy
shy-guy

Reputation: 1

sed Error "No such file or directory"

Here is my program:

    #!/bin/bash
    message=( 'somewebsite1' 'somewebsite2' 'somewebsite3' 'somewebsite4' )

for i in "${message[@]}" do longUrl=$(sed -ne 's/.*\(https\{0,1\}:\/\/[^"]*\).*/\1/p' "$i" | head -n 1) if test "$longUrl"; then echo "Shortening Url $longUrl ..." shortUrl=$(curl -s https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d "{'longUrl': '$longUrl'}" | python -c 'import json, sys; print(json.load(sys.stdin)["id"])') message=${message/$longUrl/$shortUrl} printf "%s\n" "$i" >> file.txt fi done </pre>

I am trying to shorten the URL by putting all of them into an array, but after I run it, I get the following error:

sed: somewebsite1: No such file or directory
sed: somewebsite2: No such file or directory
sed: somewebsite3: No such file or directory
sed: somewebsite4: No such file or directory

Thanks!

Upvotes: 0

Views: 3412

Answers (1)

l0b0
l0b0

Reputation: 58798

If you give sed an argument it will treat it as a path. You need to give the input on standard input:

sed -e '...' <<< "$i"

Additionally, if you're new to shell programming you may want to post the resulting working script to Code Review for tips.

Upvotes: 1

Related Questions