Rclone and bash's $@ built in function

What is the problem you are having with rclone?

It is not directly involved with rclone I think, but rclone is used, so I think I am asking for a little help with the command...
The problem is that a bash built in function is not being expanded as the flag that I need rclone command to read and execute.
More details below.

What is your rclone version (output from rclone version)

rclone v1.56.0

  • go/version: go1.16.5
  • go/linking: static
  • go/tags: none

Which OS you are using and how many bits (eg Windows 7, 64 bit)

  • os/version: linuxmint 19.2 (64 bit)
  • os/kernel: 4.15.0-153-generic (x86_64)
  • os/type: linux
  • os/arch: amd64

Which cloud storage system are you using? (eg Google Drive)

Mega

The command you were trying to run (eg rclone copy /tmp remote:tmp)

"$RCLONEBIN" mount "$SERVPROVIDER:/${REMFOLDER}" "$HOME/${SERVPROVIDER}/${REMFOLDER}" "$@" &

where:

  • $RCLONEBIN is a variable that expands to the full path and name of the rclone binary installed in my system.
  • $SERVPROVIDER is a variable that expands to the name of the cloud storage provider selected at runtime.
  • $REMFOLDER is a variable that expands to the name of the remote folder that I want to mount in my local system.
  • $HOME is auto explained...
  • $@ is a bash built in function that should expand to the flag that I want rclone to read and execute, in this case the flag I want to execute is "--vfs-cache-mode writes" (without the quotes)
  • & is a bash built in function that lets put the bash run command in the background.

NOTE:
The flag that the bash function $@ should run is stored in another bash script that is run before the rclone command, and this command is like this:

source $HOME/bin/servprovider_mount_yad --vfs-cache-mode writes

So, this bash script runs first, the command should invoke and load the second script that has the main rclone command and then at last, I expect to $@ get expanded to the said flag in the command above.
But the fact is that it seems the flag is not being sent the rclone command.

The rclone config contents with secrets removed.

[MEGA]
type = mega
user = user@emailprovider.com
pass = blablablabla

A log from the command with the -vv flag

2021/08/29 18:07:26 DEBUG : rclone: Version "v1.56.0" starting with parameters ["/usr/bin/rclone" "mount" "MEGA:/Documents" "/home/user/MEGA/Documents" "-vv"]
2021/08/29 18:07:26 DEBUG : Creating backend with remote "MEGA:/Documents"
2021/08/29 18:07:26 DEBUG : Using config file from "/home/user/.config/rclone/rclone.conf"
2021/08/29 18:07:31 DEBUG : fs cache: renaming cache item "MEGA:/Documents" to be canonical "MEGA:Documents"
2021/08/29 18:07:31 INFO  : mega root 'documentos': poll-interval is not supported by this remote
2021/08/29 18:07:31 NOTICE: mega root 'documentos': --vfs-cache-mode writes or full is recommended for this remote as it can't stream
2021/08/29 18:07:31 DEBUG : mega root 'documentos': Mounting on "/home/user/MEGA/Documents"
2021/08/29 18:07:31 DEBUG : : Root: 
2021/08/29 18:07:31 DEBUG : : >Root: node=/, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Lookup: name=".xdg-volume-info"
2021/08/29 18:07:31 DEBUG : /: >Lookup: node=<nil>, err=no such file or directory
2021/08/29 18:07:31 DEBUG : /: Lookup: name=".Trash"
2021/08/29 18:07:31 DEBUG : /: >Lookup: node=<nil>, err=no such file or directory
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Lookup: name="autorun.inf"
2021/08/29 18:07:31 DEBUG : /: >Lookup: node=<nil>, err=no such file or directory
2021/08/29 18:07:31 DEBUG : /: Lookup: name=".Trash-1000"
2021/08/29 18:07:31 DEBUG : /: >Lookup: node=<nil>, err=no such file or directory
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Attr: 
2021/08/29 18:07:31 DEBUG : /: >Attr: attr=valid=1s ino=0 size=0 mode=drwxrwxr-x, err=<nil>
2021/08/29 18:07:31 DEBUG : /: ReadDirAll: 
2021/08/29 18:07:31 DEBUG : /: >ReadDirAll: item=2, err=<nil>
2021/08/29 18:07:31 DEBUG : /: Lookup: name="autorun.inf"
2021/08/29 18:07:31 DEBUG : /: >Lookup: node=<nil>, err=no such file or directory
2021/08/29 18:10:52 DEBUG : rclone: Version "v1.56.0" finishing with parameters ["/usr/bin/rclone" "mount" "MEGA:/Documents" "/home/user/MEGA/Documents" "-vv"]

Hi,
Doing some research and laboratory, I found out the reason why the "$@" bash built in function was delivering an empty value to the rclone command...

The fact is that the initial script sources the script that runs the rclone command with the "$@" function. In fact making several tests in the command line, inserting echoes and sleep commands, here and then there, found out the exact moment that the $@ loses the value received from the initial script, the script that sources de rclone command and the flag.

It turns out that the rclone command is inside a function within the script receiving the value of the flag.

Before the function executes, the value of the flag is there, I can echoe it and see it, it is ok.

But when the function executes, then poof! the $@ function returns an empty value, nada!.

So how is the situation solved? Simply put the "$@" function at the end of the line with the name that calls the function inside the sourced script. Lets say the function that runs the rclone command is called "MOUNTING", so to call the function I just:

ยดยดยด
MOUNTING "$@"
ยดยดยด

This command calls the function, the rclone command gets executed with the correct flag and there is no error, no warning, no notice, the remote folder is mounted locally using the correct flag, which in this case is "--vfs-cache-mode writes" (without quotes).

Thanks for the attention.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.