Sharing my new script - making symbolic links

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
edcompsci
Level 2
Level 2
Posts: 69
Joined: Fri Dec 21, 2012 5:25 pm

Sharing my new script - making symbolic links

Post by edcompsci »

Every time I use a script I find online I think, "Well what can I share back?"

This one simply prompts the user to put symbolic links into a folder for use as wallpapers, to take advantage of the randomly changing backgrounds option in Desktop Settings.

I hope others enjoy it. Not a huge learning curve.

Code: Select all

#!/bin/bash

# uses arithmetic... echo "$(($a + 1))"
clear

linkfolder='/path/to/folder/' 
echo "enter the number of the last symbolic link in the $linkfolder folder"
read lastnum
echo "The number you entered is $lastnum"
i="$(($lastnum + 1))"
echo "The next symbolic link will be number $i"

echo "How many wallpaper symbolic links do you want to make?"
read numlinks
echo "You entered $numlinks"
j="$(($i + $numlinks))"
echo "The number of the last link you make will be $(($j))"


####################################### loop ###########################################
while [ $i -lt $j ]
do
echo "enter the path to image $i"
read path2image
echo "making symbolic link..."
ln -s "$path2image" "$linkfolder/$i"
echo "Symbolic link made.  Verify if tihs is the first time running this script."
((++i))
done
#################################### end loop #######################################
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Sharing my new script - making symbolic links

Post by rene »

Thank you; very useful for new scripters. One remark: you can in arithmetic expansion $((..)) leave out the $ for variables such as lastnum.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: Sharing my new script - making symbolic links

Post by Termy »

Please properly indent your code; you and any readers of your code will thank me later. ;)

Example of indenting a statement and a loop:

Code: Select all

if CONDITION; then
	COMMANDS
fi

while CONDITION; do
	COMMANDS
done
Whether you use tabs or any number of whitespaces, try to be consistent.
rene wrote: Mon May 17, 2021 8:51 am Thank you; very useful for new scripters. One remark: you can in arithmetic expansion $((..)) leave out the $ for variables such as lastnum.
Fun fact: there are other times you don't need the sigil ($), such as a subscript ${Here[is_a_variable]} and a substring ${Like:These:Variables}.
I'm also Terminalforlife on GitHub.
edcompsci
Level 2
Level 2
Posts: 69
Joined: Fri Dec 21, 2012 5:25 pm

Re: Sharing my new script - making symbolic links

Post by edcompsci »

Thanks for the replies/tips
llovepancakes
Level 1
Level 1
Posts: 34
Joined: Sun Jun 21, 2020 11:02 pm

Re: Sharing my new script - making symbolic links

Post by llovepancakes »

so this puts wallpapers on a folder background of commands or things new users use and see it as a refresher in backgrounds?
Locked

Return to “Scripts & Bash”