help with setting up aliases/functions
#1
help with setting up aliases/functions
ok so I've been trying to craft myself some tools/aliases for my dev work. I first started with making aliases, but then they got too complex and so I decided to turn them into functions which get loaded up via .profile.  So Everything works fine, If I do a "source .profile" I get no errors, but whenever I log into the account I get a bunch of errors - anyone have any idea?

Here is an example (I'm using bash btw because it supports functions)

Code:
-bash-4.2$ cat ~/.profile
##### Setup Functions #####
helloworld () {
  echo "hello World!"
}
export -f helloworld
-bash-4.2$ 
-bash-4.2$ helloworld
hello World!
-bash-4.2$ source ~/.profile
-bash-4.2$ 

so the function works and was exported to my shell - but when I login or open a new shell I always get the below - I'm trying to figure out how to (cleanly) fix this

Code:
-bash: helloworld: line 1: syntax error: unexpected end of file
-bash: error importing function definition for `helloworld'




for anyone curious, here are my old aliases using csh.  most of them didn't work because of limitations of aliases and using command-line arguments:
Code:
alias hreplace="find . -type f -name '*.h' -exec gsed -i 's/$1/$2/g' {} \;"
alias creplace="find . -type f -name '*.c' -exec gsed -i 's/$1/$2/g' {} \;"
alias mreplace="find . -type f -name 'Makefile' -exec gsed -i 's/$1/$2/g' {} \;"
alias searchfor="find . | xargs file | grep 'text' | cut -f1 -d: | xargs grep $1"
alias dos2unix="gsed -i 's/<cr>$//g' $1"


here are my new functions using bash:
Code:
##### Setup Functions #####

#search and replace string in *.h files in current dir tree
hreplace () {
echo ""
echo "Replacing \"$1\" with \"$2\" in all *.h files in \""`pwd`"/*\""
echo ""
find . -type f -name '*.h' -exec gsed -i "s/$1/$2/g" {} \;
}
export -f hreplace

#search and replace string in *.c files in current dir tree
creplace () {
echo ""
echo "Replacing \"$1\" with \"$2\" in all *.c files in \""`pwd`"/*\""
echo ""
find . -type f -name '*.c' -exec gsed -i "s/$1/$2/g" {} \;
}
export -f creplace

#search and replace string in "Makefile" files in current dir tree
mreplace () {
echo ""
echo "Replacing \"$1\" with \"$2\" in all \'Makefile\" files in \""`pwd`"/*\""
echo ""
find . -type f -name 'Makefile' -exec gsed -i "s/$1/$2/g" {} \;
}
export -f mreplace

#search for a text string in all text files in current dir tree
searchall () {
printf '\n'
find . | xargs file | grep 'text' | cut -f1 -d: |  xargs grep $1
printf '\n';
}
export -f searchall

#search for a text string in all *.c files in current dir tree
csearch () {
printf '\n'
find . | xargs file | grep 'text' | cut -f1 -d: | grep .c$ | xargs grep $1
printf '\n';
}
export -f csearch

#search for a text string in all *.h files in current dir tree
hsearch () {
printf '\n'
find . | xargs file | grep 'text' | cut -f1 -d: | grep .h$ | xargs grep $1
printf '\n';
}
export -f hsearch

#search for a text string in all "Makefile" files in current dir tree
msearch () {
printf '\n'
find . | xargs file | grep 'text' | cut -f1 -d: | grep Makefile$ | xargs grep $1
printf '\n';
}
export -f msearch


here is an example of these functions/aliases in action:
Code:
-bash-4.2$ searchall __inline__

./fm.c://#define INLINE __inline__
./driver.h://#define __inline__ /**/
./m68kconf.h://#define INLINE static __inline__
./musa/m68kconf.h://#define INLINE static __inline__

-bash-4.2$ csearch __inline__

./fm.c://#define INLINE __inline__

-bash-4.2$ hsearch __inline__

./driver.h://#define __inline__ /**/
./m68kconf.h://#define INLINE static __inline__
./musa/m68kconf.h://#define INLINE static __inline__

-bash-4.2$ creplace __inline__ __inline  

Replacing "__inline__" with "__inline" in all *.c files in "/usr/people/develop/dev/dgen/first_try/dgen-sdl-1.23/*"

-bash-4.2$ csearch __inline

./fm.c://#define INLINE __inline

-bash-4.2$ hsearch __inline

./driver.h://#define __inline__ /**/
./m68kconf.h://#define INLINE static __inline__
./musa/m68kconf.h://#define INLINE static __inline__

-bash-4.2$ hreplace __inline__ youAintGonnaFoolMeAgainSucka

Replacing "__inline__" with "youAintGonnaFoolMeAgainSucka" in all *.h files in "/usr/people/develop/dev/dgen/first_try/dgen-sdl-1.23/*"

-bash-4.2$ hsearch __inline


-bash-4.2$ hsearch Foo

./driver.h://#define youAintGonnaFoolMeAgainSucka /**/
./m68kconf.h://#define INLINE static youAintGonnaFoolMeAgainSucka
./musa/m68kconf.h://#define INLINE static youAintGonnaFoolMeAgainSucka

-bash-4.2$ 
gijoe77
Tezro

Trade Count: (1)
Posts: 644
Threads: 34
Joined: Jun 2018
Find Reply
09-08-2018, 05:11 AM


Messages In This Thread
help with setting up aliases/functions - by gijoe77 - 09-08-2018, 05:11 AM
RE: help with setting up aliases/functions - by dexter1 - 09-08-2018, 02:55 PM
RE: help with setting up aliases/functions - by gijoe77 - 09-09-2018, 08:42 AM
RE: help with setting up aliases/functions - by johnnym - 09-12-2018, 08:13 AM
RE: help with setting up aliases/functions - by gijoe77 - 09-12-2018, 11:01 AM
RE: help with setting up aliases/functions - by johnnym - 09-12-2018, 05:56 PM
RE: help with setting up aliases/functions - by gijoe77 - 09-13-2018, 10:21 PM
RE: help with setting up aliases/functions - by TruHobbyist - 09-14-2018, 11:56 AM
RE: help with setting up aliases/functions - by gijoe77 - 09-15-2018, 02:39 AM
RE: help with setting up aliases/functions - by gijoe77 - 09-15-2018, 03:53 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)