0
function copy_nfs_files {
        [ -f /proc/self/mountstats ] && cp /proc/self/mountstats $1/proc-self-mountstats.$2 >/dev/null 2>&1
        [ -f /proc/net/rpc/nfsd ] && cp /proc/net/rpc/nfsd $1/proc-net-rpc-nfsd.$2 >/dev/null 2>&1
}

This bash function copies two files /proc/self/mountstats and /proc/net/rpc/nfsd. What is the meaning of $1/proc-self-mountstats.$2? I see $1 just before file name and $2 at the end of file?

I understand that $0 is the basename, $1 the first arg, $2 the second arg, and so on. What I want to know is what it will yield when they are using like $1/proc-self-mountstats.$2. Let's suppose $1 = 123 and $2 = 100. You mean it will become 123/proc-self-mountstats.100?

I googled around to get the meaning but did not get anything around on this.

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
kulfi
  • 466
  • 4
  • 18

2 Answers2

0

What I want to know is what it will yield when they are using like $1/proc-self-mountstats.$2. Let's suppose $1 = 123 and $2 = 100. You mean it will become 123/proc-self-mountstats.100?

Yes, that's right. The expanded values are joined together with the literal parts to form one big string.

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
-2

Outside a function $1 stands for the first argument of your script. Inside a function $1 stands for the first argument to the function.

stephanmg
  • 708
  • 5
  • 17
icy
  • 13
  • 3