Skip to content

bash scripting: combine var=$(…) and var=${var%%…} lines?

Is it possible and, if yes, how to convert the following expression to one-liner? Simple DEV=${(lsblk -no KNAME,MODEL | grep ‘ModelNAME’)%%’ModelNAME’} doesn’t work Answer zsh allows you to combine parameter expansions. Bash does not. For either bash or POSIX sh (both of which su…

mmap does not work as expected (return random 0xdeadbeef)

I am writing c++ on linux7arm and the physical address is referring to a memory block (that can be accessed/changed by other peripherals) when I map a page of physical address space to the local address space and try to read it, it works fine and show the expected data BUT not all the time. if I write a scrip…

OS for Docker Image – Flavors

I’m very curious if most people are simply using Ubuntu for the majority of Linux flavors out there for their Docker images or if they’re using others. Can you tell me if you are using Ubuntu and if not why..and what else are you using? Is Ubuntu the defacto flavor just in general? Answer Many peo…

Reading tabular data from a line in bash [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 7 years ago. Improve this question I need to check if the pin that user gives exists and if exists then display their names and…

Running a shell script for a certain duration

I want to be able to run a script on Linux shell (bash) for a certain duration and sleep for a different duration. I’ve written something like the following snippet. However, I see only the sleep happening correctly but the execution stops after first execution. The response I get is ./script.sh: line 3…

Root autentication on a Python program

I have the root password saved in a variable. How I can give the root authorization at my program? This can be an example: Answer It is impossible to do it in the way you try. Your program is already started under some non-root user and you cannot change it inside this program. You can spawn other process whi…

SED : Remove last four characters from filename

I had list of files in the folder named test_images as below i want to rename all file by removing last four characters from each of them as How can i do it using sed ? Any suggestion will be appreciated. Thanks in advance 🙂 Answer if your file names don’t have spaces, you can: (under your test_images d…