# Catching empty ARGS

**URL:** <https://discourse.julialang.org/t/catching-empty-args/13724>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 19, 2018, 6:27pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724 "2018-08-19T18:27:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)\
**Post date:** [August 19, 2018, 6:27pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724/1 "2018-08-19T18:27:26Z")

</div>

I’m trying to check if there are any `ARGS` had been sent from the command line, using the below:

```
@show ARGS
localARGS = if findfirst(ARGS) == nothing ["arg1", "arg2"] else ARGS end 

```

But got the below error:

> ERROR: LoadError: syntax: space before “[” not allowed in “nothing [”

So, I recoded it as:

```
localARGS = if findfirst(ARGS) == nothing
                    ["arg1", "arg2"]
            else
                    ARGS
            end 

```

I got an error, that:

> ERROR: LoadError: TypeError: non-boolean (String) used in boolean  
> context

I also tried:

```
name = (ARGS[1] == nothing ? "arg1" : ARGS[1])

```

But got the below error:

> ERROR: LoadError: BoundsError: attempt to access 0-element  
> Array{String,1} at index [1]

And tried:

```
name = isdefined(:ARGS) ? ARGS[1] : "arg1"

```

But ended with below error:

> ERROR: LoadError: ArgumentError: isdefined: too few arguments  
> (expected 2)

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [August 19, 2018, 6:37pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724/2 "2018-08-19T18:37:18Z")

</div>

How about

```julia
name = isempty(ARGS) ? "arg1" : ARGS[1]

```

If you really want something like your first piece of code then a sprinkling of semi-colons is needed. (The extra brackets don’t appear to be needed but personally I’d have them in for reassurance.)

```julia
localARGS = ( if findfirst(ARGS) == nothing ; ["arg1", "arg2"] ; else ARGS ; end )

```

Though again, I’d replace the `findfirst` with `isempty`.

---

<div class="post-metadata">

**Author:** ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)\
**Post date:** [August 19, 2018, 6:52pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724/3 "2018-08-19T18:52:00Z")

</div>

> [@dawbarton](#):
>
> name = isempty(ARGS) ? “arg1” : ARGS[1]

This worked fine, thanks a lot.

> [@dawbarton](#):
>
> localARGS = ( if findfirst(ARGS) == nothing ; [“arg1”, “arg2”] ; else ARGS ; end )

This did not work when I send arguments to the file, I got the below error:

> ERROR: LoadError: TypeError: non-boolean (String) used in boolean context

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [August 19, 2018, 8:37pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724/4 "2018-08-19T20:37:35Z")

</div>

Ok, it appears `findfirst` has changed its behaviour between v0.6 and v1.0; on v0.7 `findfirst(["hello"])` gives the deprecation warning

```julia
Warning: In the future `findnext` will only work on boolean collections. Use `findnext(x->x!=0, A, start)` instead.

```

As such, I’d stick with

```julia
localARGS = ( if isempty(ARGS) ; [“arg1”, “arg2”] ; else ARGS ; end )

```

---

<div class="post-metadata">

**Author:** ![hasanOryx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hasanoryx/32/5373_2.png) [@hasanOryx](https://discourse.julialang.org/u/hasanOryx)\
**Post date:** [August 19, 2018, 8:46pm UTC](https://discourse.julialang.org/t/catching-empty-args/13724/5 "2018-08-19T20:46:41Z")

</div>

> [@dawbarton](#):
>
> localARGS = ( if isempty(ARGS) ; [“arg1”, “arg2”] ; else ARGS ; end )

I got

> ERROR: LoadError: syntax: invalid character ““”

Fixed it to:

`localARGS = ( if isempty(ARGS) ; ["arg1", "arg2"] ; else ARGS ; end )`

Thanks
