I found a weather function for bash from searching google, and started to finesse it. This is what I have so far, any tips to finesse it even more?
Code:
# Based on code by Crouse at www.bashscripts.org
weather() {
declare -a WEATHERARRAY
WEATHERARRAY=('lynx -dump "[URL]?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+${1}&btnG=Search" | grep -A 18 -m 1 "Current:" | sed -e 's/^[ ]*//' | cut -d '|' -f 1-5 ')
echo Weather for the zipcode of $1:$'
' ${WEATHERARRAY[@] } }
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash addelementtoarray() { local arrayname=$1
Code: #!/bin/sh #System commands and other configurable. IPT=/sbin/iptables IP6T=/sbin/ip6tables IPST=/usr/sbin/ipset MODP=/sbin/modprobe GET=/usr/bin/wget INT_NET=192.168.1.0/24 .....
I can find lots of tutorials in how to use if, then, else. However, how do I define a variable inside the function? SEE>> Code: for c in $ISO Also, am I using the 'test' command correctly( -/+ week as valid test)?
I'm making a small script for searching and doing some operations with photos, but I'm kinda stuck on this little function:
Code:
function findallformat { prefix="" if [ $1 = -pre ] then
[code]....
That function should find for every file with a certain type; and you can specify a prefix using a "-pre" followed by the prefix that you want to search. The format should be "stackable", so you can use as many types that you want, without repeating the same function on the code.
Example: findallformat -pre IMG_ .JPG .CR2 #That should search files that start with "IMG_" and finishes with .JPG and .CR2. My problem it's that, when I try to use it on the script, it says "bash: syntax error near `token' unexpected `}'"
I was wondering if possible in bash for a variable to take the value of a function, I mean the function returns a value and a variable will take it. example:
I am doing some Linux kernel programming for my research project. I need to record the timestamp (by using cpuid and rdtsc) when an interrupt handler (top half) is first invoked. Due to the time critical nature of the problem itself, I have to do the timestamping inside the interrupt handler itself (the first operation when the handler is called). However, I understand that tasks that are not so time critical should be deferred to a tasklet function (bottom half) for processing because other interrupts are disabled in a (top-half) interrupt handler. I am currently out of idea on how I can pass the timestamp information that I have obtained in the interrupt handler to the corresponding tasklet function.
I wanted to make an alias with arguments (like in cshell) which is in bash done by functions. The function must simply perform a command (nedit), append the arguments from the cli and make it run in the background (adding &).
So here is the function in a naive attempt:
Code:
when using the command
Code:
Code:
How can i use arguments and still start it in background? In cshell it was like:
If you set or export an environment variable in bash, you can unset it. If you set an alias in bash, you can unalias it. But there doesn't seem to be an unfunction.
Consider this (trivial) bash function, for example, set in a .bash_aliases file and read at shell initialization.
function foo () { echo "bar" ; }
How can I clear this function definition from my current shell? (Changing the initialization files or restarting the shell doesn't count.)
I have trouble with using an alias inside aash function. I would like to ssh into multiple machines by executing:ssh machine To achieve this, I put something like the following into my ~/.bashrc:
I have taken into count spacing of functions as a reason for not working. Can you get this function to work on your machine? quickfind () { find . -maxdepth 2 -iname "*$1*" }
It does not print the retired output but find . -maxdepth 2 -iname "*$1*" does work. What is wrong? quickfind () { f ind . -maxdepth 2 -iname "*$1*" ; }
If I run this from the command line I don't get an error but no output? I am not running this inside a script but from the command line. I want to be able to run any function () from the command line. I have more functions that I can't get to work? tt () { tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> " }
I want to set a key binding in bash for "history-search-backward" readline command to a combination of Control+some other key (I'm using 2 as an example), but I'm unable to do so. in fact, I'm unable to alter or add bindings to Control+key combinations.
After several tries my ~/.inputrc now looks like this
But it doesn't work and bind -p | grep "-2" gives nothing. If I try something without the control key:
I can search in the history by prssing the sequence C + - + 2.
bind -p gives control in C form, for example:
I've tried different formats in my inputrc:
But nothing works.
works if I press Escape followed by 2.
Setup: Fedora 11: Bash version 4.0.23(1) GNU Readline 5.2 (according to the man page)
I have packer installed for AUR packages, but I want to be able to use the pacman command for both. I think I will need a function for this -- what I mean is that whenever I use pacman, it will try using packer and if that fails (invalid option) it will use pacman-color. It could also decide which program to use based on the arguments. I can't just use packer (alias pacman='sudo packer') because packer doesn't have some options like -R to remove packages. I want to always use it to install and upgrade packages however, because It can install from the default repositories as well as AUR.
Does someone know how to accomplish this, or could point me in the right direction? I'm new to bash scripting. error (e.g. pacman -V prints packer: Option '-V' is not valid.).
I just started writing bash scripts and have a little question about the text editors. I now use gedit which I really like (don't like emacs for some reason), but I do miss some function for inserting/removing comment signs (in this case # for bash scripts) on a whole block of text. For example in Matlab you can simply mark a whole block and comment/uncomment all of it at once. Is this possible in gedit (via some plug-in or something?), or maybe in some other nice editor you can recommend?
This should be a simple thing to accomplish, but I can seem to figure it out. Essentially, I want to have a bash alias or function that will let me recursively grep the current directory. A while back I added this to my .bashrc:
Code:
alias rg="grep -r --exclude=*/.svn/* --exclude=*.swp"
This works fine, (and also ignores any svn and vim swp files), and I can call it like:
Code:
rg foo *
However, 99.999% of the time, I am only interested in searching in the current directory, so the "*" is a bit redundant. Also, I would say 5-10% of the time, I am typing faster than thinking and forget the "*", so grep just sits there trying to read from stdin. It's a pretty minor thing, but ideally I'd like to be able to just type:
Code:
rg foo
I've tried creating a function to handle this:
Code:
function rg(){ grep -r --exclude=*/.svn/* --exclude=*.swp $1 * }
but it behaves exactly the same as the alias above. escaping the "*" with 's doesn't work, and neither does trying `pwd` (or even a hard-coded path) in its place.
fit a surface i.e. W(x,y) using svdfit() provided by "Numerical Recipes in C". svdfit() is written for curve fitting and not for surface fitting.But one can use svdfit(), as claimed by authors of NR book, to do surface fitting. On page 680 of NR book, authors have given a hint on how to use svdfit() for fitting a surface. But I have not understood it.This link may be helpful (Chapter 15 th is relevant here.):[URL]This is my problem:
Code: I have a set of 100 numbers. I want to fit a 2-Dimensional function W(x,y) to these numbers.
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
Code: #!/bin/bash trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c echo "Press ctrl+c during 5 sec loop" for ((i=0;i<5;i++)); do
[Code]...
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
I have a question about calling an asm function from C....It doesn't work unless I create an asm variable to hold the value of the function in....Why?Here's the code that doesn't work...
asmfile.s - version one Code: .section .data mydata: .ascii "this is the message! .equ mylen, . - mydata
I want to use backtrace() function to debug a crash issue. I tried this sample code to see how backtrace works. backtrace() function always returns 0 with the below code. Is there any kernel configuration that needs to be set for proper working of backtrace?
#include <execinfo.h> #include <stdio.h> #include <stdlib.h> /* Obtain a backtrace and print it to stdout. */ void print_trace (void)
Can you offer me the code about fmod() in C. I want to know how this function work, i am very interested in it because i have no idea to implement it, i want to know... how to write the function... not 'how to use the function' can anyone post the source codes of this function here?
i have an open source application that was developed in C++ (it uses objects and namespaces all over the place). I also have another application that was developed in C. Now i am trying to insert the code made in C into C++ application, but when i do that , i get this error on compilation of the source code:
Code: error: 'mpi_init_vars' was not declared in this scope the function mpi_init_vars() is not part of object oriented programming and it doesn't belong to any scope, it was compiled into an object file and i am linking it with all objects of C++ application.
How can invoke the C function from C++ object oriented code?