[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command for swapping of two files or two dirs?
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: command for swapping of two files or two dirs? |
Date: |
Fri, 26 Mar 2021 21:21:21 +0100 |
swap() { declare t=$SRANDOM$SRANDOM ; [[ $# != 2 ]] && return 1
mv "$1" "$2$t"
mv "$2" "$1$t"
mv "$1$t" "$1"
mv "$2$t" "$2"
}
didnt test still
On Fri, Mar 26, 2021 at 9:18 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
>
> swap() { declare t= tt= ; [[ $# != 2 ]] && return 1
> mv "$1" "${t:=/tmp/$SRANDOM}"
> mv "$2" "${tt:=/tmp/$SRANDOM}"
> mv "$t" "$2"
> mv "$tt" "$1"
> }
>
> On Fri, Mar 26, 2021 at 6:11 PM Peng Yu <pengyu.ut@gmail.com> wrote:
> >
> > Hi,
> >
> > I can use mv to program a swap bash script. Or use renameat2(...,
> > RENAME_EXCHANGE) on Linux and renameatx_np(..., RENAME_SWAP) on Darwin
> > to make a swap C program.
> >
> > But since this should be a commonly used function, is there already an
> > existing well-maintained command for this purpose?
> >
> > --
> > Regards,
> > Peng
> >
- command for swapping of two files or two dirs?, Peng Yu, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?,
Alex fxmbsw7 Ratchev <=
- Re: command for swapping of two files or two dirs?, Greg Wooledge, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Peng Yu, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Eli Schwartz, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Reuti, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Peng Yu, 2021/03/26