<p>You don't need to copy your arguments into variables, you can just use <code>$1</code> directly. Anyway, this should be enough:</p>

<pre><code>#!/bin/bash
# usage : bash dump_qc.sh &lt;run id&gt; &lt;number of reads&gt;

if [ -z $1 ]; then
  echo "ERROR: at least one argument need to be given!" &gt;&amp;2
  exit 1
fi

if [ ! -z <span class="math-container">$2 ]; then
    x="-X '$</span>2'"
fi

fastq-dump --split-3 "<span class="math-container">$x" "$</span>1"
</code></pre>

CC BY-SA 4.0
2019-11-19T19:32:48.483Z
Thanks terdon for your solution. Im really beginner in bash programming. Could you please be more verbose and explain your code? :)
Skepto18
CC BY-SA 4.0
2019-11-19T15:45:29.380Z
2019-11-19T15:45:29.380Z
terdon
<p>Im trying to write a script where an optional input of -X flag can be used, or if that info is not available download all reads.</p>

<p>my script as follow:</p>

<pre><code># usage : bash dump_qc.sh &lt;run id&gt; &lt;number of reads&gt;

#run id variable.
SRR=$1

#maximum reads variable
X=$2

fastq-dump --split-3 -X <span class="math-container">${X} $</span>{SRR}
</code></pre>

<p>So, if I run the script</p>

<pre><code>bash dump_qc.sh SRR1234 100
</code></pre>

<p>Will download 100 reads from the specified SRR file.</p>

<p>What I would like to do is to make the second argument optional, if not specified download the whole data set!</p>

<fastq><bash><shell><sratoolkit>
Fastq-dump script download X spots or all
# Fastq-dump script download X spots or all

(Asked by: username_0 on 2019-11-19)

Im trying to write a script where an optional input of -X flag can be used, or if that info is not available download all reads.
my script as follow:
# usage : bash dump_qc.sh  

#run id variable.
SRR=$1

#maximum reads variable
X=$2

fastq-dump --split-3 -X ${X} ${SRR}

So, if I run the script
bash dump_qc.sh SRR1234 100

Will download 100 reads from the specified SRR file.
What I would like to do is to make the second argument optional, if not specified download the whole data set!

**Tags:** fastq, bash, shell, sratoolkit

---

## 1 answers

### Answer by username_1 on 2019-11-19. Score: 1

You don't need to copy your arguments into variables, you can just use $1 directly. Anyway, this should be enough:
#!/bin/bash
# usage : bash dump_qc.sh  

if [ -z $1 ]; then
  echo "ERROR: at least one argument need to be given!" >&2
  exit 1
fi

if [ ! -z $2 ]; then
    x="-X '$2'"
fi

fastq-dump --split-3 "$x" "$1"

> **Comments:**
> **username_0**: Thanks terdon for your solution. Im really beginner in bash programming. Could you please be more verbose and explain your code? :)  

---

