General TC > Programming & Scripting - Unofficial
Help with my bash script
ferran:
Ey guys !
Finally I fixed a little syntax problem in the stat line and it's no longer wrong.
I already have the code below:
--- Code: ---#!/bin/sh
#####
#
# Description: Bash script to edit any text file wih an GUI editor
#
# Comments: At final It will restore the original permissions
#
# NOTE: you need loaded the extension coreutils.tcz
#
# Execute with ./editfile.sh <file to edit>
#
# Name: editfile.sh
#
# Author: Ferran
#
# Date: Apr 7 2020
#
#####
## Get the arguments from commands line ##
argFile="$1"
echo "the file selected is $argFile"
## Get the permissions of the file and save it
getPerm=$(stat -c '%a' $argFile)
echo "the chmod of $argFile before was $getPerm"
## Set temporal permissions to 777 to open the file
sudo chmod 777 $argFile
## Execute the editor to open the file
editor $argFile
echo "The edition is finished."
## When comeback restore the original permissions
chmod $getPerm $argFile
setPerm=$(stat -c '%a' $argFile)
echo "the chmod is $setPerm again"
## Exit of sudo mode
exit
--- End code ---
Hurra! ;D
Navigation
[0] Message Index
[*] Previous page
Go to full version