You are not logged in.

#1 2019-08-12 01:07:42

MrEd
Member
Registered: 2018-06-26
Posts: 27

[SOLVED] Help to properly add string to command called in bash file

With all the searching I'm doing, I may be using the wrong search terms, so now I'm resorting to post what I'm trying to do.

The below code  is a set of commands executed by date in my conky program as noted by [ $TMP = 05 ]  &  [ $TMP = 06 ] is day 5 and day 6 of the month.

Question #1
In day 6 I've added $1 $2 $3 $4 to the begining of the lines.
Those commands work in the konsole, but is it the correct way to add a string to a command?

I ask because of
Question #2
If the lines of code with $1-$4 were attached to all the days in the month,
What is the console command I can run the file, but only execute the line with $2

elif [ $TMP = 05 ]
then
wkhtmltopdf -n https://www.foodnetwork.com/recipes/geoffrey-zakarian/sausage-and-pepper-grinder-3772096 ~/Downloads/Conky-Sandwich-Recipies/sausage-and-pepper-grinder-3772096.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/trisha-yearwood/cheese-stuffed-burgers-recipe-2065357 ~/Downloads/Conky-Sandwich-Recipies/cheese-stuffed-burgers-recipe-2065357.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/giada-de-laurentiis/sausage-peppers-and-onions-recipe-1916837 ~/Downloads/Conky-Sandwich-Recipies/sausage-peppers-and-onions-recipe-1916837.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/breakfast-pizza-3362560 ~/Downloads/Conky-Sandwich-Recipies/breakfast-pizza-3362560.pdf


elif [ $TMP = 06 ]
then
$1wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/tampa-cuban-sandwich-recipe-1973857 ~/Downloads/Conky-Sandwich-Recipies/tampa-cuban-sandwich-recipe-1973857.pdf
$2wkhtmltopdf -n https://www.foodnetwork.com/recipes/special-burger-sauce-3253748 ~/Downloads/Conky-Sandwich-Recipies/special-burger-sauce-3253748.pdf
$3wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/drippy-french-dip-sandwiches-recipe-2079725 ~/Downloads/Conky-Sandwich-Recipies/drippy-french-dip-sandwiches-recipe-2079725.pdf
$4wkhtmltopdf -n https://www.foodnetwork.com/recipes/guy-fieri/pepperoni-pizza-dip-recipe-1960601 ~/Downloads/Conky-Sandwich-Recipies/pepperoni-pizza-dip-recipe-1960601.pdf

I hope I've explained what I'm trying to do correctly.

Last edited by MrEd (2019-08-13 21:57:13)


MSI B85M-G43 * Dualcore 3.3GHz *-12GB ram * GT740 4GB video * Logitech USB-Marble Mouse=Trackball * System - ArchLinux-Antergos, KDE Plasma Desktop - Conky 1.10

Offline

#2 2019-08-12 05:08:25

ohnonot
...again
Registered: 2015-09-29
Posts: 4,165
Website

Re: [SOLVED] Help to properly add string to command called in bash file

What is contained in $1-4?

Offline

#3 2019-08-12 07:00:22

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: [SOLVED] Help to properly add string to command called in bash file

It's a 2d array data structure no? (day, line), bash doesn't actually have 2d arrays, but you can hack one in like
https://stackoverflow.com/questions/112 … h/11234169

Quoting the answer by 'Jahid' that looks good to me

declare -A arr
arr[0,0]=0
arr[0,1]=1
arr[1,0]=2
arr[1,1]=3
echo "${arr[0,0]} ${arr[0,1]}" # will print 0 1

Last edited by brontosaurusrex (2019-08-12 07:02:00)

Online

#4 2019-08-12 22:14:31

MrEd
Member
Registered: 2018-06-26
Posts: 27

Re: [SOLVED] Help to properly add string to command called in bash file

@ohnonot

in above post see
elif [ $TMP = 06 ] section

@brontosaurusrex
That looks promising, I just wonder if it would affect the original function of the script?
, which I realize just now I didn't explain because I still need it to do all 4 functions just by executing the script, but without calling any strings.

How it works-
What the conky-sandwich script does is on whatever day of month, it screenshots 4 webpages, converts them to an image, then rotates those images, 1 every 15 minutes to another directory for conky to read and display.

You can view the post, image of version 1 & download version 3 here if you wish
https://forums.bunsenlabs.org/viewtopic … 362#p88362


Since that post, I've been working on a conky control menu to control it in more detail.
basically, I made a copy of the original script, but instead of grabbing screenshots, it converts those pages to a pdf file.

So if user wants recipe 2, they hit button function in menu that runs the script, and it goes to the correct day, but grabs all 4 pdfs
instead of just the one the user wants, hence the need to add a string to the command that calls that day.

AS AN EXAMPLE command from terminal if I only want recipe #2
$ /home/major/.conky/My_conky/scripts/conky-sandwichV3-Final/food1-PDF.sh $2


Below is the script shortened to the first 6 days...day 6 is when I started the sad attempt to add strings to the commands.


#!/bin/bash


TMP=$( date +%d | awk '{print tolower($0)}' )

#make directory if doesn't exist
mkdir -p ~/Downloads/Conky-Sandwich-Recipies

if [ $TMP = 01 ]
then
#curl -o /home/major/.conky/My_conky/food/food1.gif -O -f https://food.fnr.sndimg.com/content/dam/images/food/fullset/2011/6/6/0/FNM-070111-Take-It-From-Here-005_s4x3.jpg.rend.hgtvcom.966.725.suffix/1371597731091.jpeg;
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/ultimate-ham-sandwich-recipe-2105834 /home/major/.conky/My_conky/food/food_dl/food.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/bobby-flay/perfect-burger-recipe-1957542 /home/major/.conky/My_conky/food/food_dl/food2.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/melissa-darabian/three-cheesesteak-sandwiches-recipe-2119851 /home/major/.conky/My_conky/food/food_dl/food3.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/cast-iron-pizza-5428725 /home/major/.conky/My_conky/food/food_dl/food4.pdf


elif [ $TMP = 02 ]
then
#curl -o /home/major/.conky/My_conky/food/food3.gif -O -f https://food.fnr.sndimg.com/content/dam/images/food/fullset/2011/6/6/0/FNM-070111-Take-It-From-Here-005_s4x3.jpg.rend.hgtvcom.966.725.suffix/1371597731091.jpeg
wkhtmltopdf -n https://www.foodnetwork.com/recipes/trisha-yearwood/deviled-egg-salad-club-sandwich-3667947 /home/major/.conky/My_conky/food/food_dl/food.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/perfect-beef-burgers-recipe-1973839 /home/major/.conky/My_conky/food/food_dl/food2.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/italian-subs-recipe-1973242 /home/major/.conky/My_conky/food/food_dl/food3.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/grilled-pizza-5289011 /home/major/.conky/My_conky/food/food_dl/food4.pdf


elif [ $TMP = 03 ]
then
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/camping-muffuletta-3738968 /home/major/.conky/My_conky/food/food_dl/food.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/perfect-pork-burgers-recipe-1973834 /home/major/.conky/My_conky/food/food_dl/food2.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/beg-sandwiches-bacon-egg-griddle-sandwiches-3363724 /home/major/.conky/My_conky/food/food_dl/food3.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/skillet-deep-dish-pizza-3566083 /home/major/.conky/My_conky/food/food_dl/food4.pdf


elif [ $TMP = 04 ]
then
wkhtmltopdf -n https://www.foodnetwork.com/recipes/katie-lee/fried-bologna-sandwich-5644724 /home/major/.conky/My_conky/food/food_dl/food.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/perfect-grilled-burgers-recipe-2108173 /home/major/.conky/My_conky/food/food_dl/food2.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/tyler-florence/the-ultimate-steak-sandwich-recipe-1947893 /home/major/.conky/My_conky/food/food_dl/food3.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/french-bread-pizzas-2247960 /home/major/.conky/My_conky/food/food_dl/food4.pdf


elif [ $TMP = 05 ]
then
wkhtmltopdf -n https://www.foodnetwork.com/recipes/geoffrey-zakarian/sausage-and-pepper-grinder-3772096 /home/major/.conky/My_conky/food/food_dl/food.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/trisha-yearwood/cheese-stuffed-burgers-recipe-2065357 /home/major/.conky/My_conky/food/food_dl/food2.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/giada-de-laurentiis/sausage-peppers-and-onions-recipe-1916837 /home/major/.conky/My_conky/food/food_dl/food3.pdf
wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/breakfast-pizza-3362560 /home/major/.conky/My_conky/food/food_dl/food4.pdf



elif [ $TMP = 06 ]
then
$1wkhtmltopdf -n https://www.foodnetwork.com/recipes/food-network-kitchen/tampa-cuban-sandwich-recipe-1973857 ~/Downloads/Conky-Sandwich-Recipies/tampa-cuban-sandwich-recipe-1973857.pdf
$2wkhtmltopdf -n https://www.foodnetwork.com/recipes/special-burger-sauce-3253748 ~/Downloads/Conky-Sandwich-Recipies/special-burger-sauce-3253748.pdf
$3wkhtmltopdf -n https://www.foodnetwork.com/recipes/ree-drummond/drippy-french-dip-sandwiches-recipe-2079725 ~/Downloads/Conky-Sandwich-Recipies/drippy-french-dip-sandwiches-recipe-2079725.pdf
$4wkhtmltopdf -n https://www.foodnetwork.com/recipes/guy-fieri/pepperoni-pizza-dip-recipe-1960601 ~/Downloads/Conky-Sandwich-Recipies/pepperoni-pizza-dip-recipe-1960601.pdf


days 7-31 go here


else

exit
sleep 3
fi

So that's how it functions, as I mentioned, If there is something in the command line that I can add that will run the script, but only execute the line with said string attached, but still keep the original function of getting all 4, having said that, idk if that's the proper way to add a string to a command.

Thankyou for the responses btw


MSI B85M-G43 * Dualcore 3.3GHz *-12GB ram * GT740 4GB video * Logitech USB-Marble Mouse=Trackball * System - ArchLinux-Antergos, KDE Plasma Desktop - Conky 1.10

Offline

#5 2019-08-12 23:04:50

MrEd
Member
Registered: 2018-06-26
Posts: 27

Re: [SOLVED] Help to properly add string to command called in bash file

After mowing the lawn and killing some much deserved weeds, I realize that @brontosaurusrex will probably work...

However, I don't know how to start it from cmd line...
would it be
$ ~/home/bashfile$2
$ ~/home/$2bashfile
or something else?


MSI B85M-G43 * Dualcore 3.3GHz *-12GB ram * GT740 4GB video * Logitech USB-Marble Mouse=Trackball * System - ArchLinux-Antergos, KDE Plasma Desktop - Conky 1.10

Offline

#6 2019-08-13 04:14:53

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: [SOLVED] Help to properly add string to command called in bash file

Yes, I'am saying
- decouple data (your sandwich urls) from commands that do something with that data (your download/display stuff)
- seems like this fake 2d array will do the x,y trick
- I'am trying to do a minimum example, so this will need more love

Example:

#!/bin/bash

# sandwitch, usage example:
# sandwitch 1 1
# How do they do it

# data store
declare -A arr
arr[0,0]="sandwitch"
arr[0,1]="lawn"
arr[1,0]="weed"
arr[1,1]="How do they do it"

# function that does something with data
dostuff() {

    echo "$1"
    # or wkhtmltopdf -n "$1" ....

}

# Call that function using provided positional parameters
dostuff "${arr[$1,$2]}"

Usage:

sandwitch 0 1
lawn

sandwitch 0 0
sandwitch

sandwitch 1 0
weed

p.s. Useful url https://www.shellcheck.net/

Last edited by brontosaurusrex (2019-08-13 04:49:13)

Online

#7 2019-08-13 04:31:21

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: [SOLVED] Help to properly add string to command called in bash file

MrEd wrote:

However, I don't know how to start it from cmd line...
would it be
$ ~/home/bashfile$2
$ ~/home/$2bashfile
or something else?

What you are looking for is called 'positonal parameters'.
http://mywiki.wooledge.org/BashGuide/Pa … _Variables
https://bash.cyberciti.biz/guide/How_to … parameters

Last edited by brontosaurusrex (2019-08-13 04:36:12)

Online

#8 2019-08-13 21:55:15

MrEd
Member
Registered: 2018-06-26
Posts: 27

Re: [SOLVED] Help to properly add string to command called in bash file

@brontosaurusrex   THANKYOU!!
The "LOVE" took me about 6 hrs to figure out how it was working with a command tongue
It wouldn't have taken so long. but didn't know that the command had to be divvied up, well that and watching Buck Rodgers all day  lol
but I have a working version of that using copy cmd for future reference.

In konsole I actually have to type bash
$ bash sandwich.sh 1 0

so, in example below on day 13 of month...
if testing this code, change the day number if it's not working..
$TMP = 13

#!/bin/bash
# sandwich, usage example:
# $ bash sandwich.sh 1 0
# sandwich 1 1
# How do they do it
# data store

TMP=$( date +%d | awk '{print tolower($0)}' )

#make directory if doesn't exist
mkdir -p ~/Downloads/Conky-Sandwich-Recipies

if [ $TMP = 13 ]
then

declare -A arr
arr[0,0]="/home/major/Downloads/as.png"                     # what your copying
arr[0,1]="/home/major/Downloads/Battle_of_the_planets.jpg"  # what your copying
arr[1,0]="/home/major/Downloads/beetle.jpg"                 # what your copying
arr[1,1]="/home/major/Downloads/goosebumps2.jpg"            # what your copying
# function that does something with data
dostuff() {

    #echo "$1"
    # or wkhtmltopdf -n "$1" ....
    cp "$1" /home/major/Downloads/Conky-Sandwich-Recipies/ # copy destination

}

# Call that function using provided positional parameters
dostuff "${arr[$1,$2]}"

else

exit
sleep 3
fi

Edit:
I guess that's what you ment by decouple the links/commands but didn't realize it.

Last edited by MrEd (2019-08-14 21:28:00)


MSI B85M-G43 * Dualcore 3.3GHz *-12GB ram * GT740 4GB video * Logitech USB-Marble Mouse=Trackball * System - ArchLinux-Antergos, KDE Plasma Desktop - Conky 1.10

Offline

Board footer

Powered by FluxBB