Skip to main content
Add question mark; use code markup for paths and variable names.
Source Link
njsg
  • 13.8k
  • 1
  • 29
  • 29

I want to make a bash script that symlink files for me instead of doing this manually. In my mind the workflow would be something like this :

Question 1 : What is the path of the file/folder to be the source ? ( user input the source )

Question 2 : What is the path of the destination ? ( user input destination )

And then I would take this input and make it variable $SOURCE$SOURCE and $DESTINATION$DESTINATION

Then I would just run something like :

mkdir -p $DESTINATION 
ln -s "$SOURCE" "$DESTINATION"

The script should forget the variables after every run, and also run in loop until user decides to quit it.

Also if a user input a destination that ends with a different filename as is often desired, how I can mkdir the directory but exclude the file name?

Like /root/files/1/root/files/1 and I want to symlink it to /var/files/2/var/files/2. Being "2" just a different name for file "1". How can I make my script that smart?

Sorry if this is a stupid question, I'm just new to this world and this script is going to be one of the most complex I ever wrote.

I want to make a bash script that symlink files for me instead of doing this manually. In my mind the workflow would be something like this :

Question 1 : What is the path of the file/folder to be the source ( user input the source )

Question 2 : What is the path of the destination ? ( user input destination )

And then I would take this input and make it variable $SOURCE and $DESTINATION

Then I would just run something like :

mkdir -p $DESTINATION 
ln -s "$SOURCE" "$DESTINATION"

The script should forget the variables after every run, and also run in loop until user decides to quit it.

Also if a user input a destination that ends with a different filename as is often desired, how I can mkdir the directory but exclude the file name?

Like /root/files/1 and I want to symlink it to /var/files/2. Being "2" just a different name for file "1". How can I make my script that smart?

Sorry if this is a stupid question, I'm just new to this world and this script is going to be one of the most complex I ever wrote.

I want to make a bash script that symlink files for me instead of doing this manually. In my mind the workflow would be something like this :

Question 1 : What is the path of the file/folder to be the source ? ( user input the source )

Question 2 : What is the path of the destination ? ( user input destination )

And then I would take this input and make it variable $SOURCE and $DESTINATION

Then I would just run something like :

mkdir -p $DESTINATION 
ln -s "$SOURCE" "$DESTINATION"

The script should forget the variables after every run, and also run in loop until user decides to quit it.

Also if a user input a destination that ends with a different filename as is often desired, how I can mkdir the directory but exclude the file name?

Like /root/files/1 and I want to symlink it to /var/files/2. Being "2" just a different name for file "1". How can I make my script that smart?

Sorry if this is a stupid question, I'm just new to this world and this script is going to be one of the most complex I ever wrote.

Source Link
Freedo
  • 1.4k
  • 8
  • 37
  • 64

How to ask questions with a bash script and make them a variable?

I want to make a bash script that symlink files for me instead of doing this manually. In my mind the workflow would be something like this :

Question 1 : What is the path of the file/folder to be the source ( user input the source )

Question 2 : What is the path of the destination ? ( user input destination )

And then I would take this input and make it variable $SOURCE and $DESTINATION

Then I would just run something like :

mkdir -p $DESTINATION 
ln -s "$SOURCE" "$DESTINATION"

The script should forget the variables after every run, and also run in loop until user decides to quit it.

Also if a user input a destination that ends with a different filename as is often desired, how I can mkdir the directory but exclude the file name?

Like /root/files/1 and I want to symlink it to /var/files/2. Being "2" just a different name for file "1". How can I make my script that smart?

Sorry if this is a stupid question, I'm just new to this world and this script is going to be one of the most complex I ever wrote.