Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Bash - keeping complex options in files

  • 15-09-2016 8:21pm
    #1
    Registered Users, Registered Users 2 Posts: 1,093 ✭✭✭


    I just had the misfortune of my bash history going awol. In it were some complicated options (e.g dvbtune needs frequencies, symbol rates etc., all numbers that I'm going to have to find again)

    Is there any way of keeping options in a text file and getting those options on to the command line.
    The standard pipe and < redirect obviously don't work.


Comments

  • Registered Users, Registered Users 2 Posts: 1,193 ✭✭✭liamo


    I'm not familiar with dvbtune, however a quick lookup appears to indicate that it doesn't support a config file, which would have made things easier.

    That being the case, perhaps a small script is what you need where you populate and document the arguments at the beginning of the script and then call dvbtune passing those arguments to it.



    KAGY wrote: »
    I just had the misfortune of my bash history going awol. In it were some complicated options (e.g dvbtune needs frequencies, symbol rates etc., all numbers that I'm going to have to find again)

    Is there any way of keeping options in a text file and getting those options on to the command line.
    The standard pipe and < redirect obviously don't work.


  • Registered Users, Registered Users 2 Posts: 1,093 ✭✭✭KAGY


    That (dvbtune) was just an example, I'd thought of using scripts but it (any file as a pseudo config fike) seems like such an obvious thing and very close to pipes that I thought it should be possible. The closest I came to it was using eval

    Edit: or aliases, but that'd get messy quickly


  • Registered Users, Registered Users 2 Posts: 1,193 ✭✭✭liamo


    Hi

    My response to your dvbtune example applies equally to pretty much any other example.

    If a utility/command supports a config file then that is probably the most efficient way to go.

    If not, then (to me) the most efficient way to both record and document the command line arguments and to shorten the actual command is to use a script. This effectively becomes both your config file and a shortening of the command. It also reduces the likelihood of error.

    I agree that aliases would get messy quickly - depending on how you use them. I do use aliases in similar circumstances but only as a single letter shortcut to the script that I use to solve exactly the problem that you have described.

    Regards

    Liam

    KAGY wrote: »
    That (dvbtune) was just an example, I'd thought of using scripts but it (any file as a pseudo config fike) seems like such an obvious thing and very close to pipes that I thought it should be possible. The closest I came to it was using eval

    Edit: or aliases, but that'd get messy quickly


  • Registered Users, Registered Users 2 Posts: 14,049 ✭✭✭✭Johnboy1951


    KAGY wrote: »
    I just had the misfortune of my bash history going awol. In it were some complicated options (e.g dvbtune needs frequencies, symbol rates etc., all numbers that I'm going to have to find again)

    Is there any way of keeping options in a text file and getting those options on to the command line.
    The standard pipe and < redirect obviously don't work.

    history > file

    Is that what you are looking for?
    Then run some commands on the file to sort and extract what you want?

    I am probably misunderstanding ...

    history | tr -s ' ' | cut -d ' ' -f3-19 | sort > hist.txt

    That is of course keeping command and used options in the file, which might be suitable.


  • Closed Accounts Posts: 18,966 ✭✭✭✭syklops


    Yeah I dont really understand the problem OP. Yes of course you can store the settings in a file.

    Lets say you have a file called channels.txt with channel numbers and their frequencies like this:


    1 3.12
    2 3.56
    3 3.87
    4 4.01
    5 4.21
    6 4.43
    7 4.58
    8 4.76

    so column 1 is the channel number and column two is the frequency.

    What you could do is write a couple of scripts which take out the frequency when asked for the corresponding channel. For example:

    3.sh: sed -n '3p' < channels.txt | awk '{print $2}'

    That selects the 3rd line which is the 3rd channel, and prints the second column which is 3.87

    then for dvbtune you do:

    dvbtune --channel 3 --frequency `3.sh`

    Is that what you were looking for?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,093 ✭✭✭KAGY


    Thanks for the suggestions, I was wondering if there was a standard way of creating a config file for programs that don't support them, in a similar way to piping or redirection. I've just gotten too reliant on Ctrl r and forgotten exact spellings of options or port numbers previously used.
    A script is probably the way to go


  • Registered Users, Registered Users 2 Posts: 883 ✭✭✭Keplar240B


    How did you lose the bash history?
    Bleachbit deleted mine before!
    FYI its at $HOME/.bash_history
    Do you have a backup of your home directory?


  • Registered Users, Registered Users 2 Posts: 1,093 ✭✭✭KAGY


    Keplar240B wrote:
    How did you lose the bash history? Bleachbit deleted mine before! FYI its at $HOME/.bash_history Do you have a backup of your home directory?


    I'm not too sure, have a feeling it was having a few local and ssh sessions running at the same time. Happened only once before.
    I generally only backup documents but the loss
    Is no biggie, I'm going to try make up a little script " myconf [command] [conf.txt]" next time I have a few mins spare ( probably using eval and cat)


Advertisement