Parse file into bash function for bashrc [closed] - bash

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to write a function in my bashrc to make executing a python script I wrote easier, along with piping the output. Please see example:
function pythonfunction()
{
script.py $filename | less
}
I'd like the execute the function, referencing a file, i.e.
pythonfunction testfile.txt
Apologies if this is super simple, I can't see to find the answer anywhere..
For reference, I get the error:
ERROR: Unknown Option: testfile.txt
Many Thanks,

You want this:
function pythonfunction()
{
script.py "$1" | less
}

Related

Bash - How to execute paths from file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How i could execute paths from .txt in my script?
For Example:
###################
foo.txt
/home/foo_1/public/
/home/foo_2/public/
[...]
/home/foo_n/public/
Then I want my script to look for optional file in every path from the .txt.
How I can do this?
Some loop?
Greetings
Using xargs and find Utilities
Assuming your file has no extraneous data (it's hard to tell from your original post) and holds one directory path per line, you can simply use the -n or -L flags with xargs. For example, given a source file like:
/home/foo_1/public/
/home/foo_2/public/
you could invoke find like so:
xargs -I{} -L find "{}" -name "filename_to_find" < file_paths.txt
There may be ways to do this more efficiently, of course, but this seems conceptually simpler to me than writing your own read and loop statements. Your mileage (and input data quality) may vary.
You can just concatenate all of them into a single path variable
$ path=$(paste -ds: foo.txt)

Using basic sed in bash script [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm sure this is quite simple. However, it's just not working for me. What stupid thing am I doing wrong please? I am running the following shell script like this:
bash test1.sh
Here's the code:
#!/bin/bash
bluesman_a="Magic Slim"
bluesman_b=($echo "$bluesman_a" | sed "/s/Slim/Sam/")
echo $bluesman_b
I get:
syntax error near unexpected token `|'
Thanks for your time
You need to use "$(...)" to wrap a command to assign the output to a variable and you need to remove the first / in the sed replacement command. Also, you do not need to use echo to pass a variable to sed.
bluesman_b="$(sed 's/Slim/Sam/' <<< "$bluesman_a")"
Or, to replace Slim with Sam just once, use
bluesman_b="${bluesman_a/Slim/Sam}"
See 10.1. Manipulating Strings.
See the online Bash demo

How can I set up a simple Ruby app? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This should be surprisingly simple, but it eludes me. I'm trying to set up a simple command such that I can type: ruby myfile someparams and it will return something via stdio.
I want to include a gem, like https://rubygems.org/gems/github-linguist and pass something to it and see what it has as a response.
I'm a bit lost. Ideas?
Here's a sample script that just echoes its arguments:
#!/usr/bin/env ruby
puts "The arguments were:"
ARGV.each { |curr_arg| puts curr_arg }
Save this to foo.rb, then chmod a+x foo.rb. You can either move it to some location on your PATH, in which case you can just type foo.rb some args from anywhere, or you can run it explicitly from the current directory with either ./foo.rb some args or ruby foo.rb some args.

Shell script with variables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm working a shell script to admin out email system. Essentially I get the users info and grep it to get the data I need. I've ran the below commands in terminal and they work as intended but when I use the below script I get an error "Command not found". I think its trying to run the 3rd line as a command. Anyone know what could be the problem here?
read -p "Enter email address to remove from groups: " purge_email
purge=$(python /gam/gam.py info user $purge_email)
purge_chunk=$($purge | grep -A 100 "Groups:")
echo $purge_chunk
Try:
purge_chunk=$("$purge" | grep -A 100 Groups:)
the $purge should be evaluated as formatted output the way gam kicks it out in a txt file or .csv you would use as a data source for a gam script in bash.

what does the error message "[[: not found" mean [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I am debugging a bash shell script, and I am getting this error message:
[[: not found
The line number it points to is the end of my outer do loop.
Any ideas?
Thanks!
Edit: here is the script: https://github.com/stephenh/git-central/blob/master/server/post-receive-hudson
The [[ is used in BASH as a builtin test condition. However, it doesn't work in regular Bourne shell that many systems default to when running things like cronjobs, etc.
Are you putting the shebang (#! /bin/bash) as the first line of your shell scripts? Is this a cronjob? Can you print out the value of $RANDOM (Bash will print out a value, Bourne will not)?
Show us the program that's giving you this problem, and tell us about the system it's running on (Linux? Solaris? Intel? Cygwin?) maybe we can figure it out.

Resources