Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: aus9 on July 15, 2023, 09:40:00 AM
-
Hi
most tiimes, a script that cats a line of text into a /pathway2/file works for me.
I am close on this one
all the lines in a terminal look like
> line1
> line 2 etc
my script is also pasting a tce.install script so I use EOF and that looks good as
> EOF
Up the top I change the demiliter to ZZZ and the rest of the lines look good until the last line
which reads as
> ZZZ
but that is supposed to be end of the file.
I have used ctrl + c to close down attempted input
Any clues ?
here is my top middle and bottom lines
( I have checked with echo that the variables are good)
cat > $P/usr/local/share/$P/files/$GET <<ZZZ
# tce.install
EOF
ZZZ
thanks for reading
-
It’s hard to follow script posts with very fragmented lines of code. Post the full script or a bigger portion of the code.
-
Have you tried to add it with double quotes like this example.
cat > /etc/resolv.conf << "EOF"
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
-
I don't know whether I've understood the problem correctly but for me:
tc@box:~$ cat > bbb <<ZZZ
> cat > ccc <<EOF
> ls
> EOF
> ZZZ
tc@box:~$ cat bbb
cat > ccc <<EOF
ls
EOF
tc@box:~$ . ./bbb
tc@box:~$ cat ccc
ls
looks like nested here-files work.
-
Hi Rich
Please mark as solved.
The solution was a test based on patrikg reply but with a small change away from ZZZ
cd /tmp && sudo su
cat > test << "EOF2"
#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
echo "run as root now exitting"
exit 1
fi
P=get-chromium
TCDIR=/etc/sysconfig/tcedir/optional
# tce.install
###########
mkdir -p $P/usr/local/tce.installed
cat > $P/usr/local/tce.installed/$P << 'EOF'
#!/bin/sh
[ -f /var/run/dbus/pid ] || /usr/local/etc/init.d/dbus start
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed
# now we put into member's tcedir
cd $TCDIR
cp /tmp/$P.tcz* .
EOF2
Note that I am reluctant to post full code, as I am simple coder, I need to build the get TCE and then test it. I have a fair chance I need to improve it and do not want for others to point out all my mistakes....before I get a chance to see some for myself. ;D
Note this is a private TCE built for private purposes so I am allowed to autostart dbus for this target member group. The size of the download and the resultant TCE may scare some members on arm so I suspect very few will want it.
Thanks for reading
-
Hi aus9
Please mark as solved. ...
Done. :)
-
Hi Rich sorry full script fails I am going to have to post it.
can you remove solved and in next post I will have to show full output
the end shows
> EOF2
I press enter expecting to return to prompt but what I see is
> EOF2
>
-
server error in attempting to post...so a clickable txt file link to show what I was attempting.
https://www.dropbox.com/scl/fi/bbkk2xfmh4uu555lmp2ye/forum.txt?rlkey=x7utnunbipvdkyrad68w2m8y5&dl=0
ok just spotted that my first echo has multiple double quotes..I will remove and retest
EDIT2 Nope still fails
my brain needs a rest. thanks for reading
-
Hi aus9
... can you remove solved ...
Removed. :o
-
Hi aus9,
In Your script You are assigning variables inside the here-file. This is funny and tricky but may cause brain damage )
tc@box:~$ cat aaa
cat > bbb << EOF2
N=abc
cat > $N << EOF
ls
EOF
EOF2
tc@box:~$ . ./aaa
tc@box:~$ cat bbb
N=abc
cat > << EOF
ls
EOF
Can You rewrite Your script at least to move variables definitions out of the here-file fragment?
Welcome to hell scripting!
-
Variable expansion happens as the script is written too. Can be really tricky
Why do you need to write the script from a script? Can you just include the script as a file?
-
Thanks Paul_123
I am glad others are seeing some issue too.
Lets drop this. I can upload it as a file -> in my build script use wget to get it and include it the submission under src/
Hi jazzbiker
I try to have as much text stuff inside my build script. But I give up on this one.
The build script includes a help file, well more of a howto as I will be leaving it to the victim oops I mean the member to maintain their get-script ;D
and thanks for your feedback
Hi Rich
Please mark as solved and at your discretion change subject to something like
variable expansion inside a here-file issue or anything you think might better describe what happened.
-
You could also test to use some another variable substitution, with the curly brackets.
Like this. or do you need the dollar sign variable in the script you make, you need to escape that character because of the variable substitution.
cat > ${N} << EOF
cat > \${N} << EOF
or like your way.
cat > \$N << EOF
-
Hi aus9
... Please mark as solved and at your discretion change subject to something like
variable expansion inside a here-file issue ...
Done.
-
You could also test to use some another variable substitution, with the curly brackets.
Like this. or do you need the dollar sign variable in the script you make, you need to escape that character because of the variable substitution.
cat > ${N} << EOF
cat > \${N} << EOF
or like your way.
cat > \$N << EOF
Hi patrikg,
Sorry but not
tc@box:~$ cat aaa
cat > bbb << EOF2
N=abc
cat > ${N} << EOF
ls
EOF
EOF2
tc@box:~$ . ./aaa
tc@box:~$ cat bbb
N=abc
cat > << EOF
ls
EOF
The issue aus9 faced is related to the variables expansion as Paul_123 noted. This is not syntax error. Don't sit to play dice with the devil. Simply don't do it )
Have a nice Core!
-
I can't get this of my head, just remembers that linux use two variables settings.
First you have the shell variables, which is not transferred between parent to child.
And you have something called environment variables. that stays between parent to child.
So if you want the variable to stay between parent to child you need to export it.
If i don't misunderstand your problem it seems to maybe be that the shell spawn's another shell and don't inherit the variable between parent to child.
So maybe when you assign your variable within your shell, just add the command export in front of it like this:
export N="Test"
not like this:
N="Test"
Lets play with this like this.
> TEST="Test"
> echo $TEST
Test
> bash
> echo $TEST
> exit
exit
> echo $TEST
Test
> export TEST
> bash
> echo $TEST
Test
> exit
exit
> export TEST1="Test2"
> bash
> echo $TEST1
Test2
> exit
exit
-
Hi patrikg,
You are quite right about exported variables. But if we are discussing the issue that broke aus9's script it crawls from another grim door named "here-files" or maybe "here-documents". Are You acquainted with this topic?
-
the issue that broke aus9's script...crawls from another grim door...
Hi, Andrey. Thanks for making me laugh ;D
What I like best about GNU/Linux is that there are no "Keep Out" signs anywhere. Other OSes seem not to have grim doors and crawling things--but that's only because the user is not allowed to look around.
-
Hi patrikg,
You are quite right about exported variables. But if we are discussing the issue that broke aus9's script it crawls from another grim door named "here-files" or maybe "here-documents". Are You acquainted with this topic?
Yes I am familer with this type of word and there meaning.
Okey I get it, I think.
Like the good movie Inception (https://www.imdb.com/title/tt1375666/), nested/recursion things like dream in a dream, and what that is being supported with heredoc or herefile.
-
I would try 1000 other approaches before considering a nested here document. I don't like pain.
-
Hi, Andrey. Thanks for making me laugh ;D
What I like best about GNU/Linux is that there are no "Keep Out" signs anywhere. Other OSes seem not to have grim doors and crawling things--but that's only because the user is not allowed to look around.
Hi Bruno,
I like You validate my jokes about shell ) But, seriously, I'm scared with it ( It doesn't play fairly. Still probably this is my personal attitude, I wrote a lot in various assemblers so You can believe me I am quite comfortable without any doors and even walls at all ) Nice that You keep calm and happy using shell! Hope we will appeal to You as the last resort when the next time shell will put the gun to the head of the next innocent programmer threatening to push the trigger. Damn, I am frightening myself. Time to stop )
-
I would try 1000 other approaches before considering a nested here document. I don't like pain.
Well, this is said by man who enjoy shell! Worth believing.
-
Yes I am familer with this type of word and there meaning.
Okey I get it, I think.
The trouble occurs because inside the here-file fragment assignments are not performed, while variables expansion takes place. Inside the here-file the text is simply text, not the source. Try to examine aus9's script from this point of view.