Search code examples
linuxuser-controls

How to add user input box that will change path for the rest of the script in Linux


I am creating a script that requires directories to be changed contingent upon a subjects number, which is determined by the user. Instead of having a user manually edit the code, I want a box to pop up asking

What is the subject number: emsint____FSL

where the "____" is a number for the user to enter. Once this number is entered, I want it automatically changed throughout the rest of the code (i.e. every instance the ____ appears).

# Location of Subject
cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data
mkdir emsint____FSL

cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS_data_emsint____FSL
mkdir session1 session2

cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsint___FSL/session1 
mkdir control exper1 exper2

Solution

  • While you asked for a popup box input, I don't think that is really needed, as you can keep all your user interaction at the keyboard (not requiring a mouse click).

    If I understand your Q correctly, this should work for you:

    #!/bin/bash
    printf "What is the subject number? "
    read subNum
    
    # Location of Subject
    cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data
    mkdir emsint"${subNum}"FSL
    
    cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS_data_emsint"${subNum}"FSL
    mkdir session1 session2
    
    cd /mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data/emsint"${subNum}"FSL/session1
    mkdir control exper1 exper2
    

    There are other short-cuts and code-reductions that could be done here, most notably

    #!/bin/bash
    dataDir="/mnt/netshare/imaging/emoProc_MS_Intv_NMSS/data"
    
    printf "What is the subject number? "
    read subNum
    
    # Location of Subject
    cd "$dataDir"
    mkdir emsint"${subNum}"FSL
    
    cd "${dataDir}/emsint${subNum}FSL"
    mkdir session1 session2
    
    cd "${dataDir}/data/emsint${subNum}FSL/session1"
    mkdir control exper1 exper2
    

    IHTH