Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4546512
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:57:52+00:00 2026-05-21T15:57:52+00:00

I’m currently writing a bash script which loads video files up to to YouTube

  • 0

I’m currently writing a bash script which loads video files up to to YouTube using GoogleCL.

As I’m doing this uploading stuff in a loop (because there can be multiple video files) I would like to check if each file had been uploaded successfully before I upload the next one.

The command google youtube post --access unlisted --category Tech $f (where $f represents the file) outputs a string which tells me whether the upload has been successful or not.

But I don’t know how to redirect that “return string” into a variable to do check the successs.

That’s what I have:

for f in ./*.ogv ./*.mov ./*.mp4
do
    if [[ '*' != ${f:2:1} ]]
    then
        echo "Uploading video file $f"

        # How to put the return value of the following command into a variable?
        google youtube post --access unlisted --category Tech $f > /dev/null

        # Now I assume that the output of the command above is available in the variable RETURNVALUE
        if [[ $RETURNVALUE == *uploaded* ]]
        then
            echo "Upload successful."
        else
            echo "Upload failed."
        fi
    fi
done

Can anybody help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:57:52+00:00Added an answer on May 21, 2026 at 3:57 pm

    My guess is that you could depend on the error code from the google command as well (I’m assuming it returns error if it failed to upload, but you should probably double check this).

    for f in ./*.ogv ./*.mov ./*.mp4; do
      if [[ '*' != ${f:2:1} ]]; then
    
        echo "Uploading video file $f"
        if google youtube post --access unlisted --category Tech "$f" > /dev/null
        then
          echo "Upload successful."
        else
          echo "Upload failed."
        fi
    
      fi
    done
    

    A common misconception is that if wants a bracketed expression to evaluate, this is not true, if always takes a command and checks the error status; usually this command is [ which is an alias for test, which evaluates the expression. (And yes, I’d be surprised if there isn’t an optimized shortcut to make it go faster inside bash, but conceptually it’s still true).

    Capturing output is done via backticks, like so

    result=`command argument a b c`
    

    or using $()

    result=$(command argument a b c)
    

    but it’s probably better to use the error code in this case.

    EDIT:
    You have a funny if thing in your function.. I didn’t notice at first, but it can be avoided if you enable nullglob shell option (this will make ./*.mov to expand to the empty string, if there are no files). Also, quote that $f or it’ll break if your file names contain spaces

    shopt -s nullglob
    for f in ./*.ogv ./*.mov ./*.mp4; do
      echo "Uploading video file $f"
      if google youtube post --access unlisted --category Tech "$f" > /dev/null
      then
        echo "Upload successful."
      else
        echo "Upload failed."
      fi
    done
    

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.