Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7913797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:55:39+00:00 2026-06-03T13:55:39+00:00

I have this bash code: #!/bin/bash ################################################### # Variables # BACKIFS=$IFS IFS=$’\n’ db_file=$PWD/test path_db=$PWD

  • 0

I have this bash code:

#!/bin/bash



###################################################
# Variables
#
BACKIFS=$IFS
IFS=$'\n'
db_file="$PWD/test"
path_db="$PWD"
check_first_start="$PWD/status"
num_args=$#
###################################################


###################################################
# Fist time that program start
#
function check_before_start(){
if [ ! -f "$path_db/status" ];then
    pass_2=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")
    if [ $(echo $pass_2 | awk -F"@_@" '{print $1}') != $(echo $pass_2 | awk -F"@_@" '{print $2}') ];then
        yad --title "Errore" --text "Le password sono differenti, riprovare..."
        check_before_start
    fi
    pass=$(echo $pass_2 | awk -F"@_@" '{print $1}')
    touch "$path_db/status"
fi
type_of=$(file $db_file | cut -f2 -d':' | sed '/ /s/^ //' | cut -f1 -d' ')
if [ "$type_of" = "ASCII" ]; then
    pass_2=$(yad --form --field "Password:H" --field "Retype Password:H" --separator="@_@" --title "Password" --image="dialog-password")
    if [ $(echo $pass_2 | awk -F"@_@" '{print $1}') != $(echo $pass_2 | awk -F"@_@" '{print $2}') ];then
        yad --title "Errore" --text "Le password sono differenti, riprovare..."
        check_before_start
    fi
    pass=$(echo $pass_2 | awk -F"@_@" '{print $1}') 
    encrypt_db
fi
}
###################################################


###################################################
# Check exit status
#
function exit_script(){
if [ $? != 0 ] ; then
    type_of=$(file $db_file | cut -f2 -d':' | sed '/ /s/^ //' | cut -f1 -d' ')
    if [ "$type_of" = "ASCII" ]; then
        encrypt_db
    fi
    exit 0
fi
}
###################################################


###################################################
# Encryption functions
#
function encrypt_db(){
echo $pass | gpg --passphrase-fd 0 -o $path_db/enc_db --cipher-algo=aes256 -c $db_file
mv $path_db/enc_db $db_file
}
###################################################


###################################################
# Decryption functions
#
function check_gpg_pwd_decrypt(){
if [ $? != 0 ] ; then
    yad --title "Errore Password" --text "È stata inserita una password errata, riprovare..." --width=450 --height=150
    decrypt_db
fi
}

function decrypt_db(){
pass=$(yad --form --field "Password:H" --separator="" --title "Password" --image="dialog-password")
echo $pass | gpg --passphrase-fd 0 -o $path_db/out_db --cipher-algo=aes256 -d $db_file
check_gpg_pwd_decrypt
mv $path_db/out_db $db_file
}
###################################################


###################################################
# Read data from db
function read_data_from_db(){
choosed_num=$(cat $db_file | sed -n ${line}'p' | cut -f${c1},${c2} -d'.' | tr '.' ' ')
cifra_1=$(echo $choosed_num | cut -f1 -d' ')
cifra_2=$(echo $choosed_num | cut -f2 -d' ')
yad --text "Riga -------><b>${line}</b>\nCifra $c1: --><b>$cifra_1</b>\nCifra $c2: --><b>$cifra_2</b>"
}
###################################################


###################################################
# Read from user the line, c1 and c2 numbers and check these values
#
function input_info(){
info=$(yad --form --field "Numero riga" --field "Prima cifra" --field "Seconda cifra" --separator="-" --title "Input Info")
line=$(echo $info | cut -f1 -d'-')
c1=$(echo $info | cut -f2 -d'-')
c2=$(echo $info | cut -f3 -d'-')
if [ $line -lt 1 ] || [ $line -gt 32 ]; then
    yad --text "Errore: il numero di linea deve essere compreso fra 1 e 32" --title "Errore"
    input_info
fi
if [ $c1 -lt 1 ] || [ $c1 -gt 4 ] || [ $c2 -lt 1 ] || [ $c2 -gt 4 ]; then
    yad --text "Errore: le cifre devono essere comprese fra 1 e 4" --title "Errore"
    input_info
fi
}
###################################################


###################################################
# Main
check_before_start
input_info
decrypt_db
read_data_from_db
encrypt_db
exit 0
###################################################

I have a problem because if I input a wrong password I get this error error: cannot mv file.
I don’t know why but this script executes the mv command (inside the decrypt_db function) 2 times O.o

I cannot understand how to fix it and how it is possible that the decrypt_db has this behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:55:40+00:00Added an answer on June 3, 2026 at 1:55 pm

    When the wrong password is entered, function check_before_start calls itself once more. Each of those invocations arrive at the call to encrypt_db, which in turn calls mv, so it is called two times. You need to exit ot of the outer invocation of check_before_start (e.g. using return) after it calls itself the second time due to invalid password.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code like this: #!/usr/bin/env bash test_this(){ export ABC=ABC echo some output
I have code like this, which processes a CSV file: #!/bin/bash while read line
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
I have a Jekyll blog, I am trying to switch from this {:lang='bash'} #!/bin/sh
I have a bash script that looks like this: #!/bin/sh previousRelease=`git describe --tags --match
I have a script that looks like this #!/bin/bash function something() { echo hello
I have a code snippet, as follows. #!/bin/bash filename=tmp_list_filenames line_index=0 cat $filename | while
This is my code for a bubble sort on n numbers: #!/bin/bash echo -n
Consider the following code snippet: #!/bin/bash #This program tests the if statement in bash.
I have a number of shell scripts that all look like this: #!/bin/bash cd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.