0

I want to take file from different directory and pass it to a function as an argument. I have been at this for hours but I can not get it to work. So far I have tried this

#!/bin/bash

myfile=/home/$USER/Desktop/Programs/Files/asd.bam

 function mate()
{ 
    samtools index $arg

    echo "$arg"
 }

mate $myfile

I check argument with echo command but It shows empty.

Thanks in advance.

3
  • 2
    Have you really been searching on this topic? Even a simple google search gives a lot of info? Commented Apr 9, 2019 at 11:41
  • Yes I have and I wrote, I have been trying to get it work for hours. Maybe I am dim-witted or something. Commented Apr 9, 2019 at 11:44
  • Hm, ok. Just replace $arg with $1. Ex echo "$1". And it will work. Commented Apr 9, 2019 at 11:50

1 Answer 1

1

You haven't defined arg and hence its is empty (undefined). $1 within the function will be the first argument passed.

function mate()
{ 
    arg="$1"
    samtools index "$arg"
    echo "$arg"
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.