#!/bin/bash sysdir=$1 dir="dir" case $dir in dir) cd $sysdir foldername=$(basename $sysdir) backupname=$foldername$date cd .. stf_b="tar -czvpf /home/pc/script/backup/$backupname.tar.gz $foldername" $stf_b ;; file) echo "Ok" ;; esac 

if this line

 stf_b="tar -czvpf /home/pc/script/backup/$backupname.tar.gz $foldername 

replace with this

 stf_b="tar -czvpf ~/script/backup/$backupname.tar.gz $foldername 

nothing works, can anyone actually explain why?

  • maybe you run the script on behalf of another user? for example from under the crown? - KoVadim
  • No, on behalf of the user, I just go into the same script, change these lines and one works and the second does not, run the same. - hovdev
  • @S1lllver exactly how to run? I do not see the "magic line" at the beginning of the script - rjhdby
  • made the edit, it is there, otherwise I would have started it ./script testdir / test - hovdev
  • one
    Just use /home/$USER - vp_arth

1 answer 1

From the POSIX standard

It is a sign that the sign is backlit, and backsloche

...

This is a double-quotation. The parameter '@' has special meaning inside double-quotes

POSIX specifically about tilde

A "tilde-prefix" consists of an unquoted tilde character .......

!!!! unquoted tilde character !!!!

Inside double quotes, a tilde ( ~ ) turns into a pumpkin, i.e. just a character with no special meaning

The best option, in your case, add at the very beginning of the script

 $MY_DIR=~ 

and then use it

  • pc: x: 1000: 1000: afgan ,,,: / home / pc: / bin / bash - hovdev
  • Coincides like - hovdev
  • one
    @ S1lllver "It's bash, baby!" like a joke :) If you want complex logic, then perl / python is in your hands. If you want to quickly and on the knee, then you have to put up with the imperfections of the world and build crutches on the shell - rjhdby
  • one
    For the answer, make HOME = ~ and it really works, thank you a kind person)) - hovdev
  • one
    @ S1lllver and what do you have $ HOME equal to before you HOME = ~ trying to do? - jfs