Answers.Body: <p>Welcome to SE!</p>
  <p>Although this is about downloading CiviCRM files, there is nothing specific to CiviCRM so this might get closed as off-topic.  But we try to be friendly, especially to newcomers :-)</p>
  <p>How are you calling the script?  There are a few variables that need to be set.</p>
  <p>Maybe try putting <code>echo &quot;File is $civi_download_prod&quot;</code> before the last line to confirm the variable is being set correctly.</p>
  <p>A few observations on the rest of the script:</p>
  <ul>
  <li>Is this the start of a more comprehensive downloader that will also handle downloads for other CMSes? It seems unnecessarily complex for what it is actually doing.</li>
  <li>I'm not clear what you gain by the first <code>wget</code> since you're always downloading it if it exists.  <code>if wget -q $download_link</code> would be simpler.</li>
  <li>You don't need <code>cv flush</code> before extracting the files.</li>
  <li>It would be preferable to construct the file name once, not twice.</li>
  </ul>
  <p>So how about:</p>
  <pre><code>[ $cms_instance == &quot;drupal&quot; ] &amp;&amp; extension=&quot;tar.gz&quot;
  [ $civi_type_version == &quot;p&quot; ] &amp;&amp; download_file=&quot;civicrm-$civi_version-$cms_instance.$extension&quot; &amp;&amp; download_link=&quot;https://download.civicrm.org/$download_file&quot;                                                                                                      
  
  if wget -q $download_link                                                             
  then
        echo -e '\e[93m=======================================\033[0m'
        echo &quot;The version of CiviCRM you asked is available in the server&quot;
        echo &quot;Instance $cms_instance&quot;
        echo &quot;The actual CiviCRM version is $civi_name&quot;
        echo -e '\e[93m=======================================\033[0m'
  else
        echo -e '\e[93m=======================================\033[0m'
        echo -e '\e[93m\033[31m No CiviCRM version have been found\033[31m'
        echo -e '\e[93m=======================================\033[0m'
        exit 1
  fi
  
  [ $cms_instance == &quot;drupal&quot; ] &amp;&amp; [ $civi_type_version == &quot;p&quot; ] &amp;&amp; tar -xzf $download_file &amp;&amp; rm $download_file     
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-10T10:34:57.817Z
Answers.LastActivityDate: 2023-08-10T10:34:57.817Z
Answers.UserDisplayName: Aidan
Body: <p>I have created a script that updates civicrm version of the instance I want. This script install with the <code>wget</code> command the choosed civicrm version from the civicrm download website. <strong><a href="https://download.civicrm.org/%E2%80%A6" rel="nofollow noreferrer">https://download.civicrm.org/…</a></strong>
  I use a variable to get the civicrm version and the <code>tar -xzf</code> command to extract the zipped folder.</p>
  <p><code>cms_instance = &quot;drupal&quot;</code> and <code>civi_type_version = &quot;p&quot;</code></p>
  <p>The line with the problem : <strong>tar -xzf $civi_download_prod</strong>
  And I got this error in the command line : <strong>tar : the -- 'f' option needs an argument</strong></p>
  <p><strong>Here is the script :</strong></p>
  <pre><code>[ $cms_instance == &quot;drupal&quot; ] &amp;&amp; extension=&quot;tar.gz&quot;  
  [ $civi_type_version == &quot;p&quot; ] &amp;&amp; download_link=&quot;https://download.civicrm.org/civicrm-$civi_version-$cms_instance.$extension&quot; 
  
  if wget -S --spider $download_link  2&gt;&amp;1 | grep 'HTTP/1.1 200 OK' &gt; /dev/null 2&gt;&amp;1; 
  then
        echo -e '\e[93m=======================================\033[0m'
        echo &quot;The version of CiviCRM you asked is available in the server&quot;
        echo &quot;Instance $cms_instance&quot;
        echo &quot;The actual CiviCRM version is $civi_name&quot;
        echo -e '\e[93m=======================================\033[0m'
        wget $download_link
  else
        echo -e '\e[93m=======================================\033[0m'
        echo -e '\e[93m\033[31m No CiviCRM version have been found\033[31m'
        echo -e '\e[93m=======================================\033[0m'
        exit 1
  fi
  
  civi=&quot;civicrm&quot;
  civi_download_prod=&quot;$civi-$civi_version-$cms_instance.$extension&quot;
  
  # clear cache civi
  cv flush
  
  [ $cms_instance == &quot;drupal&quot; ] &amp;&amp; [ $civi_type_version == &quot;p&quot; ] &amp;&amp; **tar -xzf $civi_download_prod** &amp;&amp; rm -rf $civi_download_prod
  </code></pre>
  <p>Command line : <strong>tar : the -- 'f' option needs an argument</strong></p>
  
Tags: <civicrm-home>
Title: tar : the -- 'f' option needs an argument
ThreadText: # tar : the -- 'f' option needs an argument
  
  (Asked by: username_0 on 2023-08-10)
  
  I have created a script that updates civicrm version of the instance I want. This script install with the wget command the choosed civicrm version from the civicrm download website. https://download.civicrm.org/…
  I use a variable to get the civicrm version and the tar -xzf command to extract the zipped folder.
  cms_instance = "drupal" and civi_type_version = "p"
  The line with the problem : tar -xzf $civi_download_prod
  And I got this error in the command line : tar : the -- 'f' option needs an argument
  Here is the script :
  [ $cms_instance == "drupal" ] && extension="tar.gz"  
  [ $civi_type_version == "p" ] && download_link="https://download.civicrm.org/civicrm-$civi_version-$cms_instance.$extension" 
  
  if wget -S --spider $download_link  2>&1 | grep 'HTTP/1.1 200 OK' > /dev/null 2>&1; 
  then
        echo -e '\e[93m=======================================\033[0m'
        echo "The version of CiviCRM you asked is available in the server"
        echo "Instance $cms_instance"
        echo "The actual CiviCRM version is $civi_name"
        echo -e '\e[93m=======================================\033[0m'
        wget $download_link
  else
        echo -e '\e[93m=======================================\033[0m'
        echo -e '\e[93m\033[31m No CiviCRM version have been found\033[31m'
        echo -e '\e[93m=======================================\033[0m'
        exit 1
  fi
  
  civi="civicrm"
  civi_download_prod="$civi-$civi_version-$cms_instance.$extension"
  
  # clear cache civi
  cv flush
  
  [ $cms_instance == "drupal" ] && [ $civi_type_version == "p" ] && **tar -xzf $civi_download_prod** && rm -rf $civi_download_prod
  
  Command line : tar : the -- 'f' option needs an argument
  
  **Tags:** civicrm-home
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-08-10. Score: 1
  
  Welcome to SE!
  Although this is about downloading CiviCRM files, there is nothing specific to CiviCRM so this might get closed as off-topic.  But we try to be friendly, especially to newcomers :-)
  How are you calling the script?  There are a few variables that need to be set.
  Maybe try putting echo "File is $civi_download_prod" before the last line to confirm the variable is being set correctly.
  A few observations on the rest of the script:
  
  Is this the start of a more comprehensive downloader that will also handle downloads for other CMSes? It seems unnecessarily complex for what it is actually doing.
  I'm not clear what you gain by the first wget since you're always downloading it if it exists.  if wget -q $download_link would be simpler.
  You don't need cv flush before extracting the files.
  It would be preferable to construct the file name once, not twice.
  
  So how about:
  [ $cms_instance == "drupal" ] && extension="tar.gz"
  [ $civi_type_version == "p" ] && download_file="civicrm-$civi_version-$cms_instance.$extension" && download_link="https://download.civicrm.org/$download_file"                                                                                                      
  
  if wget -q $download_link                                                             
  then
        echo -e '\e[93m=======================================\033[0m'
        echo "The version of CiviCRM you asked is available in the server"
        echo "Instance $cms_instance"
        echo "The actual CiviCRM version is $civi_name"
        echo -e '\e[93m=======================================\033[0m'
  else
        echo -e '\e[93m=======================================\033[0m'
        echo -e '\e[93m\033[31m No CiviCRM version have been found\033[31m'
        echo -e '\e[93m=======================================\033[0m'
        exit 1
  fi
  
  [ $cms_instance == "drupal" ] && [ $civi_type_version == "p" ] && tar -xzf $download_file && rm $download_file
  
  
  ---
  
  