-
Win-bash use
Hello! Congratulations on the victorious holiday on May 9, a great victory!
I am modifying the script, and I want it, for the first modification, not to download and unpack gcc-11.1.0, if it already exists.
I am amazed at the syntax of the bash, and even get stumped.
1.) The variable local loc_var = 23 is not declared in the second function, although it is local, I expect some human syntax, I cannot understand this.
I looked for an error twice for an hour and a half, thinking, then closing one line at a time with a grid.
2.) The sequential execution of the script is interrupted, part of the program is not executed
Code:
echo "loc_var"
echo "\" loc_var \ "outside function = $ loc_var"
echo "Os"
echo
echo "\" loc_var \ "outside function = $ loc_var"
# $ loc_var outside function =
# No, $ loc_var not visible globally.
echo "\" global_var \ "outside function = $ global_var"
# $ global_var outside function = 999
# $ global_var is visible globally.
echo
interrupting my sequential execution, for no reason, as if jumping somewhere, without any logic, I'm shocked, I don't understand at all.
This is an error message, and it's probably skewed to my second function, sstest2 (), line 62 of code.
vse - is a message from the first function
Code:
vse
local: =: not a legal variable name
local: 23: not a legal variable name
return: bad non-numeric arg `loc_var '
D: \ src>
How do you first write a function that compares the name of a folder with some text string and outputs a boolean yes or no to the surface?
From all this I just do not know in which direction to dig!
In the operating system Windows 7 I am on Win-Bash the script. I will use in a team strip so D: \ Win-Bash \ Bash.exe D: \ SRC \ build-gcc.sh
Code:
#! /bin/bash
GCC_VERSION="11.1.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools.
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files.
# xcode-select --install
# sudo apt install wget
# wget https://google.com
wget -V
# get the source code
cd $WORKDIR
#yourfilenames=`ls ./*.txt`
yourfilenames=`ls ./`
for eachfile in $yourfilenames
do
echo $eachfile
done
stest(){
local loc_var = 23
local X="a"
local Y="b"
if [ "${X}" = "${Y}" ]; then
echo "they're the same"
else
echo "they're not the same"
fi
local nazva=$1
local bl=0
echo "vse"
return loc_var
}
stest
echo "loc_var"
echo "\"loc_var\" outside function = $loc_var"
echo "Os"
echo
echo "\"loc_var\" outside function = $loc_var"
# $loc_var outside function =
# No, $loc_var not visible globally.
echo "\"global_var\" outside function = $global_var"
# $global_var outside function = 999
# $global_var is visible globally.
echo
#function_name() {
sstest2(){
local loc_var2 = 24
local loc_var = 23
#local temp=`ls ./`
local nazva=$1
local bl=0
echo "Ugu"
for eachfile in $temp
do
if [ "${eachfile}" = "${nazva}" ]; then
bl=1
echo "Aga"
fi
done
return bl
}
sstest2
function_name
[ -d "D:\src\gcc-11.1.0" ] && echo "Da. -D:\src\gcc-11.1.0"
## ÈËÈ ##
[ ! -d "D:\src\gcc-11.1.0" ] && echo "Net. -D:\src\gcc-11.1.0"
#[ $(ls -ld "$ISDIR" | cut -c1) = 'd' ] &&
# echo "YES, $ISDIR is a directory." ||
# echo "Sorry, $ISDIR is not a directory"
# echo "[ -d "$DIR/gcc-${GCC_VERSION}.tar.gz" ]"
# echo "&&"
# echo "[ -d "$1" ]"
#if ![ -d "$DIR/gcc-${GCC_VERSION}.tar.gz" ]; then
if function_name "$DIR/gcc-${GCC_VERSION}.tar.gz" ; then
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
# wget https://ftp.wayne.edu/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
# gzip -d gcc-${GCC_VERSION}.tar.gz
#tar --extract gcc-${GCC_VERSION}.tar
tar xzvf gcc-${GCC_VERSION}.tar.gz
elif ! function_name "$DIR/gcc-${GCC_VERSION}" ; then
# tar xzf gcc-${GCC_VERSION}.tar.gz
gzip -d gcc-${GCC_VERSION}.tar.gz
# tar -tf gcc-${GCC_VERSION}.tar
# tar -xv gcc-${GCC_VERSION}.tar
tar -xvf gcc-${GCC_VERSION}.tar
fi
# download the prerequisites
cd gcc-${GCC_VERSION}
./contrib/download_prerequisites
# create the build directory
cd ..
mkdir gcc-build
cd gcc-build
# build
../gcc-${GCC_VERSION}/configure \
--prefix=${INSTALLDIR} \
--enable-shared \
--enable-threads=posix \
--enable-__cxa_atexit \
--enable-clocale=gnu \
--enable-languages=all \
&& make \
&& make install
# Notes
#
# --enable-shared --enable-threads=posix --enable-__cxa_atexit:
# These parameters are required to build the C++ libraries to published standards.
#
# --enable-clocale=gnu:
# This parameter is a failsafe for incomplete locale data.
#
# --disable-multilib:
# This parameter ensures that files are created for the specific
# architecture of your computer.
# This will disable building 32-bit support on 64-bit systems where the
# 32 bit version of libc is not installed and you do not want to go
# through the trouble of building it. Diagnosis: "Compiler build fails
# with fatal error: gnu/stubs-32.h: No such file or directory"
#
# --with-system-zlib:
# Uses the system zlib instead of the bundled one. zlib is used for
# compressing and uncompressing GCC's intermediate language in LTO (Link
# Time Optimization) object files.
#
# --enable-languages=all
# --enable-languages=c,c++,fortran,go,objc,obj-c++:
# This command identifies which languages to build. You may modify this
# command to remove undesired language
-
You do not have a function called "function_name" in the code you posted.
Yet you call it several times; fix this and then retry!
Tim S.
-
Yes, I think I removed the excess. Here are the errors when running the script
Code:
D:\src>D:\win-bash\bash.exe D:\src\build-gcc.sh
they're not the same
vse
local: =: not a legal variable name
local: 23: not a legal variable name
return: bad non-numeric arg `loc_var'
D:\src>
Code:
#! /bin/bash
GCC_VERSION="11.1.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools.
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files.
# xcode-select --install
# sudo apt install wget
# wget https://google.com
# get the source code
cd $WORKDIR
stest(){
local loc_var = 23
local X="a"
local Y="b"
if [ "${X}" = "${Y}" ]; then
echo "they're the same"
else
echo "they're not the same"
fi
local nazva=$1
local bl=0
echo "vse"
return loc_var
}
stest
echo "loc_var = $loc_var"
function_name() {
local loc_var2 = 24
local loc_var = 23
#local temp=`ls ./`
local nazva=$1
local bl=0
echo "Ugu"
for eachfile in $temp
do
if [ "${eachfile}" = "${nazva}" ]; then
bl=1
echo "Aga"
fi
done
return bl
}
if ! [function_name "$DIR/gcc-${GCC_VERSION}.tar.gz" ]; then
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
tar xzvf gcc-${GCC_VERSION}.tar.gz
elif ! function_name "$DIR/gcc-${GCC_VERSION}" ; then
gzip -d gcc-${GCC_VERSION}.tar.gz
tar -xvf gcc-${GCC_VERSION}.tar
fi
# download the prerequisites
cd gcc-${GCC_VERSION}
./contrib/download_prerequisites
# create the build directory
cd ..
mkdir gcc-build
cd gcc-build
# build
../gcc-${GCC_VERSION}/configure \
--prefix=${INSTALLDIR} \
--enable-shared \
--enable-threads=posix \
--enable-__cxa_atexit \
--enable-clocale=gnu \
--enable-languages=all \
&& make \
&& make install
# Notes
#
# --enable-shared --enable-threads=posix --enable-__cxa_atexit:
# These parameters are required to build the C++ libraries to published standards.
#
# --enable-clocale=gnu:
# This parameter is a failsafe for incomplete locale data.
#
# --disable-multilib:
# This parameter ensures that files are created for the specific
# architecture of your computer.
# This will disable building 32-bit support on 64-bit systems where the
# 32 bit version of libc is not installed and you do not want to go
# through the trouble of building it. Diagnosis: "Compiler build fails
# with fatal error: gnu/stubs-32.h: No such file or directory"
#
# --with-system-zlib:
# Uses the system zlib instead of the bundled one. zlib is used for
# compressing and uncompressing GCC's intermediate language in LTO (Link
# Time Optimization) object files.
#
# --enable-languages=all
# --enable-languages=c,c++,fortran,go,objc,obj-c++:
# This command identifies which languages to build. You may modify this
# command to remove undesired language
-
I believe but do not know that local must be used only inside a bash function.
Edit: Just relooked at your code and each local appears to be inside a function.
Why don't you use someone else's code and modify it to do what you want?
Edit2: Link to someone code A shell script to download packages for, configure, build and install a GCC cross-compiler. * GitHub
Tim S.
-
Thank you! I am glad to link, in fact this is what I wanted to do (but not working).
So I exactly and expected that Local should be used only inside the Bash function.
I use inside, only inside the Bash function. I really expected that this variable nowhere can be seen from the outside.
It seems that it is not. This is amazing.
So I don't understand something in Bash syntax, or I made syntax errors, but I do not see them.
The code for the link the same gives me a lot of errors, and will need a lot of corrections.
-
Another thing: This is not valid:
Code:
$ x = 1
x: command not found
Assignments must not have spaces: