Programming :: Using An Alias Or Function Without The Newline?
May 1, 2010
I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.
Code:
$ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE=
The idea is that I'm studying c and want to change the name of the file once instead of
[code]....
View 3 Replies
ADVERTISEMENT
Jun 8, 2011
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:
alias machine='user@machine'
ssh()
{
[code]....
View 1 Replies
View Related
Jul 6, 2010
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.).
View 1 Replies
View Related
Feb 14, 2011
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.
View 2 Replies
View Related
Nov 28, 2009
I'm writing a script to replace some text that exists in about 50 .lex, .y, and .cc source code files, sometimes more than once in a file. Sometimes the text is in a multiline C comment, and other times it's within a multiline C string.
I use sed to grab the start and end of each line and wrap the new text in the old whitespace and/or quotes and Problem is, sed is changing the characters into a newline.
Is there a way to tell sed to not process escape sequences? I tried using several variations of
Code:
To no avail. Or could it be bash?
I would give up on the script and do it by hand, but this is something that I must do from time to time.
Here's the function which replaces the first occurrence found:
Code:
When $post is printed by echo, it shows the - but by the time the file is on disk, it becomes a newline. What should I do to ensure that it stays as the characters ?
View 4 Replies
View Related
Mar 11, 2011
I have a tab delimited file. I need to replace the 7th tab with a new line.
I tried the following command (but it does not work):
The above simply spits out the original file.
If I write the next command, it replaces the first tab in each line with a newline. How can I make it replace the 7th tab in each line?
View 4 Replies
View Related
Nov 22, 2010
I have several (vhdl) files containing a pattern with newline characters that I need to replace by another pattern that also contains newline characters.
I start with something like:
Code:
I want to replace it by something like:
Code:
(I need to paste some lines)
As I need to do this (very) often I want to use a shell script.
I tried:
1.
Code:
result:
Code:
2.
Code:
result:
File remains unchanged
3.
Code:
result:
Code:
4.
Code:
result:
Displays the unchanged testfile
How I can automate the pattern replacement?
Code:
View 9 Replies
View Related
Mar 8, 2009
I need to replace part of a line in a file with multiple lines, however need to separate each line with a newline is this possible?
Example, need to remove line 2
And insert line similar to below:
If the multiple lines were part of a text file, would inserting a text file automatically include newline characters?
View 1 Replies
View Related
Apr 27, 2010
I can't get x to work with a mouse so I have to use a windows computer to do that from for now. The problem is I remember there being something about windows using a newline AND carriage return and linux just using a newline. I was about to cut and paste code but the lines go on and on instead of breaking off where they did in linux. I was going to write a perl script but don't know how to add a carriage return to the end of each line.
View 3 Replies
View Related
May 21, 2011
Using xsel I pass a selection into a variable. I then check that the variable includes an embedded newline to be sure that the selection returned by xsel is complete. If the selection content preceding the newline is just a single word, the check fails to detect the newline, thus
Code:
g fnm=`xsel`
g cat <<< "$fnm"
Whatis
apropos sear
[code]....
View 14 Replies
View Related
Nov 11, 2009
I'm having a hard time figuring out why the program posted below prints an extra newline every time I type the enter key.This program is using the master pseudo-terminal to send the password and receive the output from the slave(connected to the passwd program).I suspect this has to do with the terminal line discipline(s)(2 considering the master and slave), but I can't really understand why.I have tried turning on/off several terminal special characters but to no avail.
Source code follows(compiled in x86, Slackware-13.0 - linux-2.6.31.5 - gcc 4.3.3):
Code:
View 14 Replies
View Related
Nov 16, 2010
Code:
#include <iostream>
using namespace std;
[code]...
View 1 Replies
View Related
May 18, 2010
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.
View 2 Replies
View Related
Dec 10, 2010
How do I write a regexp that matches a string that begins with whitespace or contains a newline, but not necessarily both?
View 2 Replies
View Related
May 24, 2010
I want to declare a function in a function, but had no success till now, see the error code below and visit the project at sourceforge
[Code]...
View 14 Replies
View Related
Jun 20, 2010
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]....
View 10 Replies
View Related
Apr 4, 2011
I have problem to use an alias that defined in ksh93 script,in the functions in the same script onm Linux.I definied an alias in main: alias echo='echo -e' in order that echo will read backslashes but when i executed it in function, the alias didnt work, and performewd a regular echo, without -e
cat test.ksh
#!/bin/ksh
alias echo='echo -e'
checkUsage
[code]....
View 1 Replies
View Related
Jul 15, 2010
I am trying to execute executable files in bash without adding ./ I know there must be an alias to add in .bashrc, that must be something like alias PATH=$PATH:. But this seems not to be working.
View 1 Replies
View Related
Jul 6, 2011
alias and shopt won't work in script
[Code]....
View 9 Replies
View Related
Sep 21, 2010
Okay so I have an alias that looks like this:
Code:
ALIAS sorigin {
MSG sorigin Test1
[code]...
View 1 Replies
View Related
Sep 16, 2010
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.
[code]....
View 2 Replies
View Related
Jun 4, 2010
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
[code]...
View 2 Replies
View Related
Jul 23, 2010
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)
[Code]...
View 2 Replies
View Related
May 30, 2010
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?
View 6 Replies
View Related
Jul 5, 2010
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?
View 2 Replies
View Related
May 2, 2011
I am trying to build a function inside a script.
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)?
View 7 Replies
View Related
Feb 7, 2011
I am doing a web site program and what I need is to call a C program in the PHP cloud.Do u think it would be possible? The web site would get the user input from PHP UI and pass to the C program , the C program would process the function with the user input and output the a PHP page.
View 2 Replies
View Related
Jan 4, 2011
I ask if a c++/c function is able to know its name from inside itself:
example:
Code:
int funct1(int a,b)
{
printf("%s ",funct_name());
}
or with a trick.
View 2 Replies
View Related
May 30, 2010
Code:
#!/bin/ksh
(...)
# FILL UP PARTITION
diskfillerfunction () {
[Code]....
Test 15: fill up partition /usr/bin/time: cannot run diskfillerfunction: No such file or directory
I am obviously omitting (...) a lot of the code, but the relevant part is all there. How do I 'time' a function?
View 5 Replies
View Related
Mar 26, 2010
I wrote a spinner in Perl and when I did a spinner in shell I could just run the subroutine in the background.
[code]...
In Perl, how do you run a function in a background and get the PID for that? I know PID in Perl is $$
View 2 Replies
View Related