It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am new to linux & bash, and I am working on some different scripts, but I have a few conceptual questions I need answered to help me find the best approach to what I want to do.
What is the most efficient way to store data in a bash script, and save it as a file, that another script can speedily parse?
What are some good examples of colorful bash menu's? How can I have a multi-column menu's in bash?
Can I display images in bash or would it be better to send the image info to, let's say a notify-send, and have it to display any images?
Thank you.
That's quite a potpourri of questions :-)
Firstly, the most efficient way to store data in a bash script depends entirely on the data and the processing you want done to it. If the processing will be done by bash itself, it'll probably be faster in a bash variable (size permitting). If external programs like grep, sed or awk will be processing it under the direction of bash, a file may be better.
But that's a very general guideline - you need to analyse both the data and the use of it, especially since how it's stored in the file is also important. By way of example, I wouldn't store fixed length records as an XML file if I was processing it in bash alone, since that means I'd have to write a whole lot of XML processing code for the shell. I'd probably just store it as fixed length records in a flat file.
Secondly, I have no examples for you, as bash tends to either be a command-line driven thing or, at most, a very simple menu-based thing. It's not generally used for fancy UI work.
And you can quite easily have multi-column menus, the simplest form being something like:
echo "1. Enter new contact. 4. Find contact"
echo "2. Edit contact 5. Exit"
echo "3. Delete contact"
Lastly, bash itself has no support for displaying images any more complicated than ASCII art:
|\_/|
/ # # \
( > º < )
\__V__/
/ O \
So, if you need something more complex than that, you'll probably be passing it off to an external program.
Related
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
I am new to Linux/Unix environment. I am developing a simple bash script to execute some daily drivers logic. But I need to simplify my functions by its complex codes. Are there any specific way to address these issues?
as a example, In script I need to execute this function, in wrap with predefined reference
pseudo code,
git init . --> (reference in) refer1
the refer1 should, execute as same as git init .
Please do not add functional solutions, it is already implemented
In such scenarios, the most recommended way is use terminal functions as it is. In this I realised you specifically focused on referencing a bash commands in simpler terms.
For theses scenarios can accommodate by linux alias functions.
The simpler term if alias is "aliases allow a string to be substituted for a word when it is used as the first word of a simple command." You can get more advance details by following command,
$ man alias
In this issue alias need 2 parameters, the referencing alias name, exact bash function.
$ alias reference_name='your_bash_command'
This is the solution for your problem.
$ alias refGit='git init . '
You could be interested in commands such as crontab(1) or at or batch, and you might use guile as your scripting language (it is much more expressive and powerful than bash is) or Python or Lua or Ocaml. See execve(2) which is the primitive system call used to start all programs (including your scripts from your crontab(5) file). Take care of your $PATH settings (perhaps not the same in a cron or batch job and in your terminal). See related conventions in environ(7).
The table of Linux system calls is on syscalls(2).
Please take several days to read books such as Advanced Linux Programming (online or on paper).
Consider studying for inspiration the source code of most Linux utilities, they are very often open source. Perhaps my execicar.c could interest you? (GPLv3+ code, commented but not otherwise documented).
You might be interested by changing your interactive unix shell with chsh(1). I like zsh but you might prefer fish.
I need to points a set of terminal executions in to simple reference
Have you looked into GNU parallel or into icecream ? It seems to fit your needs, and it is free software (whose source code you can study) that you can improve and adapt to them.
I am developing a simple bash script ...
As a matter of opinion, I don't recommend using GNU bash (or Tcl) for any script larger than a few dozen of lines (because bash is an unstructured language and untyped language, see these slides). Linux has many "better" (more expressive, more efficient) scripting languages. Learn them and use them.
You can create functions like in other languages:
#!/bin/bash
refer1() {
git init .
}
refer1
Functions can always be used in scripts, and work no matter how complex the command is.
Aliases must be enabled with shopt -s expand_aliases, must be escaped carefully, can only use parameters appended at the end, and must be defined in a separate parsing unit to work.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I need to write a program that is to be run as follows: <program_name>_ <space> _<file_name>_ <space> _<stuff to be written into the file>. I am new to Linux/C/Unix programming and so I need your help. From what I can understand, I need to write a program titled <program_name>, pass two parameters in the main function which are <file_name> and <stuff to be written in the file>, and then go through the code as usual, writing all the required lines. Am I going about this the right way? Also, it is mentioned that I am to create a make file out of the program. As I am thoroughly unfamiliar with Linux, I would like to know if that this would change anything. That is, would my approach to the program change because I am to make a make file out of it? Thanks for the help! :)
You should search for "beginning linux" to get some web sites that will give you the basics of navigating around in Linux, notably on the command line.
Then I'd search for "beginning vi" to learn the basics of the vi editor. If you're using a GUI, then you can simply use their simple GUI text editor.
Then I would search on "Beginning C programming linux". That will give you several links, and will get you through the basics of creating a C program and compiling it with GCC.
That should keep you in enough trouble for the short term until something clicks or you learn enough new terms to keep searching for.
Good luck!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How difficult is to develop a text editor in windows?
edit: something like this for a target: http://intype.info/home/index.php
That depends on what sort of text editor you want. For a really simple editor, you can just host an EDIT control (or RICHTEXT control), in which case you have a working editor in well under an hour. If you want to write a full-blown programmer's editor, you'd probably want to measure the time in months or years instead of minutes.
Depends on what tools you use. To develop something offering basic functionality (like Notepad) using C# and WPF or Windows Forms (or VB if that's your poison) would be pretty easy if you knew the language and the API well. Doing something similar with Python, Ruby, or something else and Tk, GTK, Qt, etc. wouldn't be terribly hard either. Same goes for Java and AWT or Swing. Any graphics toolkit with a high level language is going to give you most of the scaffolding that all you really need to do is define the layout and add some logic (opening files, saving, etc.) Developing with C or C++ (unmanaged) and the Win32 API would be much more difficult, but still relatively simple.
You could probably put together a working Notepad clone rather quickly. It gets harder as you add features. I know that with my language and toolkit of choice (Python + Tkinter) I could probably do a feature for feature clone of Notepad in a few hours, right down to appearance and UI.
Pretty easy actually:
use whatever GUI toolkit you want
add a multi line textbox control
add load/save options
compile/build/link
and you just made a poor man's notepad :)
Now seriously, what do mean with a text editor? What kind of features are you looking for? Do want something simple like notepad, something totally awesome like notepad++, or something enormous like word?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I generally need to do a fair amount of text processing for my research, such as removing the last token from all lines, extracting the first two tokens from each line, splitting each line into tokens, etc.
What is the best way to perform this? Should I learn Perl for this? Or should I learn some kind of shell commands? The main concern is speed. If I need to write long code for such stuff, it defeats the purpose.
EDIT:
I started learning sed on #Mimisbrunnr 's recommendation and already could do what I needed to. But it seems people favor awk more. So, will try that. Thanks for all your replies.
Perl and awk come to mind, although Python will do, if you'd rather not learn a new language.
Perl's a general purpose language, awk's more oriented to text processing of the type you've described.
For doing simple steam editing sed is a great utility that comes standard on most *nix boxes, but for anything much more complex than that I would suggest getting into Perl. The curve isn't that bad and it's great for writing most forms of regular text parsing. A great reference can be found here.
#!/usr/bin/env python
# process.py
import fileinput
for line in fileinput.input(): # you could use `inplace=True` parameter here
words = line.split() # e.g. split on white spaces
all_except_last = words[:-1]
print ' '.join(all_except_last)
# or
first_two = words[:2]
print ' '.join(first_two)
Examples:
$ echo a b c | python process.py
$ ./process.py input.txt another.txt
*nix tools such as awk/grep/tail/head/sed etc are good file processing tools. If you want to search for patterns in files and process them, you can use awk. For big files, you can use a combination of grep+awk. Grep for its speed in pattern searching and awk for its ability to manipulate text. with regards to sed, oftern what sed does, awk can already do them, so i find it redundant to use sed for file processing.
In terms of speed of processing files, awk is often on par, or sometimes better than Perl or other languages.
Also, 2 very good tools for getting the front and back portion of a file FAST, are tail and head. So to get last lines, you can use tail.
Best tool depends on the task to be performed, of course. Beside the usual *nix tools like sed/awk etc and programming languages (Perl, Python) cited by others, currently for the text processing I need where the original data format doesn't follow rigid parsing rules but may vary slightly, I found myself very well with Vim macros and Vimscript functions which I call inside the Vim editor.
Something like this (for the Vim uninitiated): you write the processing function(s) eg. TxtProcessingToBeDone1() on a file script.vim, source it with :source script.vim, then open the file(s) you want to edit and:
:call TxtProcessingToBeDone1()
on the whole buffer at once or as one-shot operation to be repeated on spot with #: and ## keys. Also multiple buffers/files can be processed at the same time with :bufdo and :argdo.
With a Vimscript function you can repeat all the tasks you would do on a regular editing session (search a pattern, reg-ex, substitution, move to, delete, yank, etc, etc), automate it and also apply some programming control flow (if/then).
Similar considerations apply to other advanced scriptable editors as well.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 13 years ago.
I don't know if I am a bad programmer because I often make mistakes when outputting information on a site, things like "thanx for subscribing to our service" instead of "Thanks for subscribing to our service".
I think this is because I usually don't concentrate on the spelling, my main focus is to get the functionality running perfectly. Please give me your opinion, do you concentrate on the spellings or the functionality?
If I'm writing a message which will be visible to users, I'll make sure it's clear and correct. If I'm writing a message which will only be visible to other developers, I'm slightly less careful - in particular, typos aren't really a problem, so long as I express myself clearly.
Fortunately my spelling/typing/grammar is reasonably good anyway, so I don't need to think too hard about this, but I think it is important for customer-facing text.
Developers often aren't very good at writing messages for users. It can be hard to put yourself in the position of someone who really has no idea about what's going on in the background: they just want to get their email (or whatever it is) working. If you're lucky, you may be able to get a technical writer to help compose appropriate text.
IMO attention must be paid to both. Cool logic and reliability are no excuse for crappy texts.
You could separate checking the resource from changing the source. When you do changes first change the code, test everything, then proofread the resources.
The CTO at my last job was dyslexic, and a completely brilliant programmer and manager. Every now and then I would go and make a spelling correction to one of his method or variable names (C# handles the refactoring pretty well) and it didn't really matter that much.
When there's user interface work it's much more important to spell things correctly coz it looks very shabby to have a misspelled UI.